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>
261 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&)
const;
262 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&);
263 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&)
const;
264 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&);
474 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
481 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
483 #if OPENVDB_ABI_VERSION_NUMBER >= 7
539 template<
typename Gr
idPtrContainerT>
540 inline typename GridPtrContainerT::value_type
543 using GridPtrT =
typename GridPtrContainerT::value_type;
544 typename GridPtrContainerT::const_iterator it =
546 return (it == container.end() ? GridPtrT() : *it);
550 template<
typename KeyT,
typename Gr
idPtrT>
554 using GridPtrMapT = std::map<KeyT, GridPtrT>;
555 for (
typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
558 const GridPtrT& grid = it->second;
559 if (grid && grid->getName() ==
name)
return grid;
570 template<
typename _TreeType>
601 template<
typename OtherValueType>
633 template<
typename OtherTreeType>
657 Ptr copyWithNewTree()
const;
673 #if OPENVDB_ABI_VERSION_NUMBER >= 7
712 Name type()
const override {
return this->gridType(); }
728 bool empty()
const override {
return tree().empty(); }
730 void clear()
override { tree().clear(); }
789 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
798 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
806 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
809 void pruneGrid(
float tolerance = 0.0)
override;
837 template<
typename OtherTreeType>
852 template<
typename OtherTreeType>
865 template<
typename OtherTreeType>
876 CoordBBox evalActiveVoxelBoundingBox()
const override;
878 Coord evalActiveVoxelDim()
const override;
880 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
893 TreePtrType treePtr() {
return mTree; }
900 bool isTreeUnique()
const;
904 TreeType& tree() {
return *mTree; }
927 void newTree()
override;
937 void readTopology(std::istream&)
override;
940 void writeTopology(std::ostream&)
const override;
943 void readBuffers(std::istream&)
override;
945 void readBuffers(std::istream&,
const CoordBBox&)
override;
951 void readNonresidentBuffers()
const override;
953 void writeBuffers(std::ostream&)
const override;
956 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
963 static inline bool hasMultiPassIO();
977 <<
" might not be threadsafe on this platform");
987 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1009 template<
typename Gr
idType>
1010 inline typename GridType::Ptr
1013 return GridBase::grid<GridType>(grid);
1025 template<
typename Gr
idType>
1026 inline typename GridType::ConstPtr
1029 return GridBase::constGrid<GridType>(grid);
1042 template<
typename Gr
idType>
1043 inline typename GridType::Ptr
1046 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
1047 return gridPtrCast<GridType>(grid->deepCopyGrid());
1051 template<
typename Gr
idType>
1052 inline typename GridType::Ptr
1055 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
1065 template<
typename _TreeType>
1097 template<
typename _TreeType>
1126 template<
typename _TreeType>
1167 template<
typename LeafNodeType>
1169 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1173 template<
typename RootNodeType>
1180 template<
typename TreeType>
1189 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1198 template<
typename Gr
idType>
1199 inline typename GridType::Ptr
1204 if (
grid &&
grid->type() == GridType::gridType()) {
1205 return StaticPtrCast<GridType>(
grid);
1207 return typename GridType::Ptr();
1211 template<
typename Gr
idType>
1212 inline typename GridType::ConstPtr
1215 return ConstPtrCast<const GridType>(
1216 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1220 template<
typename Gr
idType>
1221 inline typename GridType::ConstPtr
1224 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(
grid));
1228 template<
typename Gr
idType>
1229 inline typename GridType::ConstPtr
1232 return ConstPtrCast<const GridType>(
1233 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1255 template<
typename TreeT>
1261 template<
typename TreeT>
1267 template<
typename TreeT>
1274 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1275 template<
typename TreeT>
1285 template<
typename TreeT>
1293 template<
typename TreeT>
1294 template<
typename OtherTreeType>
1297 mTree(new
TreeType(other.constTree()))
1302 template<
typename TreeT>
1310 template<
typename TreeT>
1319 template<
typename TreeT>
1328 template<
typename TreeT>
1332 return Ptr(
new Grid(background));
1337 template<
typename TreeT>
1346 template<
typename TreeT>
1357 template<
typename TreeT>
1365 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1366 template<
typename TreeT>
1371 this->constTransformPtr());
1372 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1376 template<
typename TreeT>
1380 return this->copyReplacingMetadataAndTransform(*
this, xform);
1383 template<
typename TreeT>
1388 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1394 template<
typename TreeT>
1402 template<
typename TreeT>
1412 template<
typename TreeT>
1416 return this->copy();
1419 template<
typename TreeT>
1423 return this->copy();
1426 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1427 template<
typename TreeT>
1431 return this->copyReplacingMetadata(meta);
1434 template<
typename TreeT>
1438 return this->copyReplacingTransform(xform);
1441 template<
typename TreeT>
1446 return this->copyReplacingMetadataAndTransform(meta, xform);
1450 template<
typename TreeT>
1454 return this->copyWithNewTree();
1461 template<
typename TreeT>
1465 return mTree.use_count() == 1;
1469 template<
typename TreeT>
1474 if (tree->type() != TreeType::treeType()) {
1476 + tree->type() +
" to a grid of type " + this->type());
1478 mTree = StaticPtrCast<TreeType>(tree);
1482 template<
typename TreeT>
1486 mTree.reset(
new TreeType(this->background()));
1493 template<
typename TreeT>
1497 tree().sparseFill(bbox, value, active);
1501 template<
typename TreeT>
1505 this->sparseFill(bbox, value, active);
1508 template<
typename TreeT>
1512 tree().denseFill(bbox, value, active);
1515 template<
typename TreeT>
1520 const auto value = zeroVal<ValueType>() + tolerance;
1522 this->tree().prune(
static_cast<ValueType>(value));
1525 template<
typename TreeT>
1532 template<
typename TreeT>
1536 tree().merge(other.
tree(), policy);
1540 template<
typename TreeT>
1541 template<
typename OtherTreeType>
1545 tree().topologyUnion(other.
tree());
1549 template<
typename TreeT>
1550 template<
typename OtherTreeType>
1554 tree().topologyIntersection(other.
tree());
1558 template<
typename TreeT>
1559 template<
typename OtherTreeType>
1563 tree().topologyDifference(other.
tree());
1570 template<
typename TreeT>
1574 tree().evalMinMax(minVal, maxVal);
1578 template<
typename TreeT>
1583 tree().evalActiveVoxelBoundingBox(bbox);
1588 template<
typename TreeT>
1593 const bool nonempty = tree().evalActiveVoxelDim(dim);
1594 return (nonempty ? dim :
Coord());
1604 template<
typename TreeT>
1608 tree().readTopology(is, saveFloatAsHalf());
1612 template<
typename TreeT>
1616 tree().writeTopology(os, saveFloatAsHalf());
1620 template<
typename TreeT>
1625 tree().readBuffers(is, saveFloatAsHalf());
1627 uint16_t numPasses = 1;
1628 is.read(
reinterpret_cast<char*
>(&numPasses),
sizeof(uint16_t));
1631 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1632 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1633 meta->setPass(pass);
1634 tree().readBuffers(is, saveFloatAsHalf());
1642 template<
typename TreeT>
1647 tree().readBuffers(is, bbox, saveFloatAsHalf());
1649 uint16_t numPasses = 1;
1650 is.read(
reinterpret_cast<char*
>(&numPasses),
sizeof(uint16_t));
1653 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1654 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1655 meta->setPass(pass);
1656 tree().readBuffers(is, saveFloatAsHalf());
1665 template<
typename TreeT>
1669 tree().readNonresidentBuffers();
1673 template<
typename TreeT>
1677 if (!hasMultiPassIO()) {
1678 tree().writeBuffers(os, saveFloatAsHalf());
1683 uint16_t numPasses = 1;
1684 meta->setCountingPasses(
true);
1686 tree().writeBuffers(os, saveFloatAsHalf());
1687 numPasses =
static_cast<uint16_t
>(meta->pass());
1688 os.write(
reinterpret_cast<const char*
>(&numPasses),
sizeof(uint16_t));
1689 meta->setCountingPasses(
false);
1692 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1693 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1694 meta->setPass(pass);
1695 tree().writeBuffers(os, saveFloatAsHalf());
1702 template<
typename TreeT>
1710 template<
typename TreeT>
1714 tree().print(os, verboseLevel);
1716 if (metaCount() > 0) {
1717 os <<
"Additional metadata:" << std::endl;
1718 for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1719 os <<
" " << it->first;
1721 const std::string value = it->second->str();
1722 if (!value.empty()) os <<
": " << value;
1728 os <<
"Transform:" << std::endl;
1729 transform().print(os,
" ");
1737 template<
typename Gr
idType>
1738 inline typename GridType::Ptr
1741 return GridType::create(background);
1745 template<
typename Gr
idType>
1746 inline typename GridType::Ptr
1749 return GridType::create();
1753 template<
typename TreePtrType>
1757 using TreeType =
typename TreePtrType::element_type;
1762 template<
typename Gr
idType>
1763 typename GridType::Ptr
1766 using ValueType =
typename GridType::ValueType;
1769 static_assert(std::is_floating_point<ValueType>::value,
1770 "level-set grids must be floating-point-valued");
1772 typename GridType::Ptr grid = GridType::create(
1773 static_cast<ValueType
>(voxelSize * halfWidth));
1783 namespace internal {
1786 template<
typename OpT,
typename GridBaseT,
typename T,
typename ...Ts>
1787 struct GridApplyImpl {
static bool apply(GridBaseT&, OpT&) {
return false; } };
1791 template<
typename OpT,
typename GridBaseT,
typename GridT,
typename ...GridTs>
1792 struct GridApplyImpl<OpT, GridBaseT,
TypeList<GridT, GridTs...>>
1794 static bool apply(GridBaseT& grid, OpT& op)
1796 if (grid.template isType<GridT>()) {
1800 return GridApplyImpl<OpT, GridBaseT,
TypeList<GridTs...>>::apply(grid, op);
1807 template<
typename Gr
idTypeListT,
typename OpT>
1811 return internal::GridApplyImpl<OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1814 template<
typename Gr
idTypeListT,
typename OpT>
1818 return internal::GridApplyImpl<OpT, GridBase, GridTypeListT>::apply(*
this, op);
1821 template<
typename Gr
idTypeListT,
typename OpT>
1825 return internal::GridApplyImpl<const OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1828 template<
typename Gr
idTypeListT,
typename OpT>
1832 return internal::GridApplyImpl<const OpT, GridBase, GridTypeListT>::apply(*
this, op);
1838 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:192
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1079
static TreeType & tree(GridType &g)
Definition: Grid.h:1145
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:1396
A list of types (not necessarily unique)
Definition: Types.h:653
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1081
typename GridType::Ptr GridPtrType
Definition: Grid.h:1136
SharedPtr< Grid > Ptr
Definition: Grid.h:574
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:588
Abstract base class for typed grids.
Definition: Grid.h:78
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:1027
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
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:1429
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:972
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:591
virtual bool empty() const =0
Return true if this grid contains only background voxels.
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:1414
SharedPtr< TreeBase > Ptr
Definition: Tree.h:38
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:432
~Grid() override
Definition: Grid.h:641
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1146
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1321
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1133
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:770
typename TreeType::ValueType ValueType
Definition: Grid.h:1080
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:706
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:909
void setSaveFloatAsHalf(bool)
Return this grid's user-specified name.
virtual void pruneGrid(float tolerance=0.0)=0
Reduce the memory footprint of this grid by increasing its sparseness either losslessly (tolerance = ...
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:354
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1108
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1534
virtual Name type() const =0
Return the name of this grid's type.
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1090
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:592
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1091
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:39
virtual void readBuffers(std::istream &, const CoordBBox &)=0
Read all of this grid's data buffers that intersect the given index-space bounding box.
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1149
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:534
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1088
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:585
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:743
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:469
void setName(const std::string &)
Specify a name for this grid.
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...
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1755
virtual Index64 activeVoxelCount() const =0
Return the number of active voxels.
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:1452
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:1667
MetaMap::Ptr getStatsMetadata() const
Return a new MetaMap containing just the metadata that was added to this grid with addStatsMetadata.
void setIsInWorldSpace(bool)
Specify whether this grid's voxel values are in world space or in local space.
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1113
static GridClass stringToGridClass(const std::string &)
Return the class of volumetric data specified by the given string.
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:745
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1138
void setGridClass(GridClass)
Specify the class of volumetric data (level set, fog volume, etc.) that is stored in this grid.
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
virtual void writeBuffers(std::ostream &) const =0
Write out all data buffers for this grid.
std::string Name
Definition: Name.h:17
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:747
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:768
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: Types.h:123
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:730
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:910
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
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1151
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1256
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:510
static TreeType & tree(TreeType &t)
Definition: Grid.h:1115
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1132
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:471
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:898
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:575
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:436
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:1385
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:774
static TreeType & tree(GridType &g)
Definition: Grid.h:1116
virtual void readBuffers(std::istream &)=0
Read all data buffers for this grid.
std::string getName() const
Return this grid's user-specified name.
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1153
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1121
static TreeType & tree(GridType &g)
Definition: Grid.h:1086
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:758
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:712
Name name
Definition: Grid.h:535
bool isInWorldSpace() const
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1147
GridClass
Definition: Types.h:816
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:515
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1130
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:512
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Definition: Grid.h:1222
@ OPENVDB_FILE_VERSION_MULTIPASS_IO
Definition: version.h:190
_TreeType TreeType
Definition: Grid.h:1129
typename TreeType::ValueType ValueType
Definition: Grid.h:1110
uint64_t Index64
Definition: Types.h:30
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:908
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:1404
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1590
typename _TreeType::ValueType ValueType
Definition: Grid.h:580
_TreeType TreeType
Definition: Grid.h:1100
static const char *const META_GRID_CREATOR
Definition: Grid.h:351
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1712
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:1368
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:586
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:526
void setCreator(const std::string &)
Provide a description of this grid's creator.
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:897
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1739
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1078
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:1200
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1675
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:728
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1141
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1109
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1074
typename _TreeType::BuildType BuildType
Definition: Grid.h:581
@ MERGE_ACTIVE_STATES
Definition: Types.h:870
openvdb::GridBase Grid
Definition: Utils.h:33
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:1614
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:896
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...
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:760
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1103
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:572
virtual void clip(const CoordBBox &)=0
Clip this grid to the given index-space bounding box.
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:520
_TreeType TreeType
Definition: Grid.h:577
virtual Index64 memUsage() const =0
Return the number of bytes of memory used by this grid.
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:584
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:357
const Name const NamePair & type
Definition: PointAttribute.h:545
bool isTreeUnique() const
Return true if tree is not shared with another grid.
Definition: Grid.h:1463
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1120
const math::Transform & transform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:411
@ GRID_LEVEL_SET
Definition: Types.h:818
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:359
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:532
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:509
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1622
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:1245
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1142
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:481
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1089
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:148
void addStatsMetadata()
Add metadata to this grid comprising the current values of statistics like the active voxel count and...
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
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:1238
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:1543
void clearGridClass()
Remove the setting specifying the class of this grid's volumetric data.
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1152
virtual void setTree(TreeBase::Ptr)=0
Associate the given tree with this grid, in place of its existing tree.
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:1436
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:525
virtual void clear()=0
Empty this grid, setting all voxels to the background.
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:1510
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers.
Definition: Grid.h:1704
static const char *const META_FILE_DELAYED_LOAD
Definition: Grid.h:361
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1111
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1119
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1140
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:519
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1572
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:587
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:590
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1112
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1104
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
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...
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1168
~GridBase() override
Definition: Grid.h:86
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1131
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:403
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:1764
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:764
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:429
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:578
static VecType stringToVecType(const std::string &)
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
typename TreeType::ValueType ValueType
Definition: Grid.h:1139
Vec3< double > Vec3d
Definition: Vec3.h:662
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
_TreeType TreeType
Definition: Grid.h:1070
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:704
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:714
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:527
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...
VecType
Definition: Types.h:846
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1517
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1069
static std::string gridClassToMenuName(GridClass)
Return a formatted string version of the grid class.
typename GridType::Ptr GridPtrType
Definition: Grid.h:1077
typename GridType::Ptr GridPtrType
Definition: Grid.h:1107
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1073
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:511
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:434
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:755
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:1552
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:521
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1580
static std::string vecTypeToString(VecType)
Return the metadata string value for the given type of vector data.
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:981
virtual Coord evalActiveVoxelDim() const =0
Return the dimensions of the axis-aligned bounding box of all active voxels.
MergePolicy
Definition: Types.h:869
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1484
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1117
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...
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:516
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:187
tree::TreeBase TreeBase
Definition: Grid.h:26
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:602
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
Definition: Grid.h:440
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1082
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:725
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:353
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1072
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:524
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1087
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1102
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:579
std::string getCreator() const
Return the user-specified description of this grid's creator.
static std::string vecTypeDescription(VecType)
Return a string describing how the given type of vector data is affected by transformations (e....
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:358
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:1378
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:717
void setVectorType(VecType)
Specify the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this ...
Index64 memUsage() const override
Definition: Grid.h:884
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:1503
void clipGrid(const BBoxd &)
Clip this grid to the given world-space bounding box.
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:1011
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:593
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:970
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:1053
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
typename std::remove_const< ToType >::type Type
Definition: Types.h:298
Definition: ValueAccessor.h:183
GridBase(GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:493
static const char *const META_GRID_NAME
Definition: Grid.h:352
void clearVectorType()
Remove the setting specifying the type of vector data stored in this grid.
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:182
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:402
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const =0
Output a human-readable description of this grid.
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1083
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:552
const Name & name
Definition: PointAttribute.h:544
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
static const char *const META_GRID_CLASS
Definition: Grid.h:350
const math::Transform & constTransform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:412
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:766
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1471
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:1561
VecType getVectorType() const
Return the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this g...
static TreeType & tree(TreeType &t)
Definition: Grid.h:1085
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 ...
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:583
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1122
Definition: LeafBuffer.h:41
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1148
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1092
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:1809
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,...
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:514
Definition: Exceptions.h:65
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1137
static TreeType & tree(TreeType &t)
Definition: Grid.h:1144
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:1606
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:360
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:1042
Definition: Exceptions.h:13
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:356
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:762
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:438
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:824
Grid & operator=(const Grid &)=delete
Disallow assignment, since it wouldn't be obvious whether the copy is deep or shallow.
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1118
static const char *const META_VECTOR_TYPE
Definition: Grid.h:355
std::shared_ptr< T > SharedPtr
Definition: Types.h:91
double Real
Definition: Types.h:37
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:1495
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:772
static std::string vecTypeExamples(VecType)
virtual CoordBBox evalActiveVoxelBoundingBox() const =0
virtual void readNonresidentBuffers() const =0
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
GridClass getGridClass() const
Return the class of volumetric data (level set, fog volume, etc.) that is stored in this grid.
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:874
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1527
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:522
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1071
static std::string gridClassToString(GridClass)
Return the metadata string value for the given class of volumetric data.
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
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:1443
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1150
static void clearRegistry()
Clear the grid type registry.
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1101
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:490
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:735
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...
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:517
Definition: Exceptions.h:64
GridNamePred(const Name &_name)
Definition: Grid.h:533
Base class for typed trees.
Definition: Tree.h:36
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253