Go to the documentation of this file.
31 #ifndef OPENVDB_GRID_HAS_BEEN_INCLUDED
32 #define OPENVDB_GRID_HAS_BEEN_INCLUDED
45 #include <type_traits>
55 template<
typename>
class Grid;
62 template<
typename Gr
idType>
63 inline typename GridType::Ptr
createGrid(
const typename GridType::ValueType& background);
69 template<
typename Gr
idType>
77 template<
typename TreePtrType>
95 template<
typename Gr
idType>
119 #if OPENVDB_ABI_VERSION_NUMBER <= 3
148 static bool isRegistered(
const Name &type);
151 static void clearRegistry();
159 virtual Name type()
const = 0;
161 virtual Name valueType()
const = 0;
164 template<
typename Gr
idType>
165 bool isType()
const {
return (this->type() == GridType::gridType()); }
170 template<
typename Gr
idType>
174 template<
typename Gr
idType>
176 template<
typename Gr
idType>
177 static typename GridType::ConstPtr constGrid(
const GridBase::Ptr&);
178 template<
typename Gr
idType>
220 virtual void newTree() = 0;
225 virtual bool empty()
const = 0;
227 virtual void clear() = 0;
238 virtual void pruneGrid(
float tolerance = 0.0) = 0;
240 #if OPENVDB_ABI_VERSION_NUMBER >= 3
241 void clipGrid(
const BBoxd&);
280 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&)
const;
281 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&);
288 std::string getName()
const;
290 void setName(
const std::string&);
293 std::string getCreator()
const;
295 void setCreator(
const std::string&);
299 bool saveFloatAsHalf()
const;
300 void setSaveFloatAsHalf(
bool);
311 void clearGridClass();
316 static std::string gridClassToString(
GridClass);
318 static std::string gridClassToMenuName(
GridClass);
323 static GridClass stringToGridClass(
const std::string&);
337 void clearVectorType();
342 static std::string vecTypeToString(
VecType);
345 static std::string vecTypeExamples(
VecType);
348 static std::string vecTypeDescription(
VecType);
349 static VecType stringToVecType(
const std::string&);
357 bool isInWorldSpace()
const;
359 void setIsInWorldSpace(
bool);
384 virtual Index64 activeVoxelCount()
const = 0;
388 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
391 virtual Coord evalActiveVoxelDim()
const = 0;
394 virtual Index64 memUsage()
const = 0;
400 void addStatsMetadata();
466 virtual void readTopology(std::istream&) = 0;
469 virtual void writeTopology(std::ostream&)
const = 0;
472 virtual void readBuffers(std::istream&) = 0;
473 #if OPENVDB_ABI_VERSION_NUMBER >= 3
474 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
481 virtual void readNonresidentBuffers()
const = 0;
483 virtual void writeBuffers(std::ostream&)
const = 0;
492 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
499 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
504 #if OPENVDB_ABI_VERSION_NUMBER <= 3
514 static void registerGrid(
const Name& type, GridFactory);
516 static void unregisterGrid(
const Name& type);
520 math::Transform::Ptr mTransform;
557 template<
typename Gr
idPtrContainerT>
558 inline typename GridPtrContainerT::value_type
561 using GridPtrT =
typename GridPtrContainerT::value_type;
562 typename GridPtrContainerT::const_iterator it =
563 std::find_if(container.begin(), container.end(),
GridNamePred(name));
564 return (it == container.end() ? GridPtrT() : *it);
568 template<
typename KeyT,
typename Gr
idPtrT>
572 using GridPtrMapT = std::map<KeyT, GridPtrT>;
573 for (
typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
576 const GridPtrT& grid = it->second;
577 if (grid && grid->getName() == name)
return grid;
588 template<
typename _TreeType>
619 template<
typename OtherValueType>
651 template<
typename OtherTreeType>
653 #if OPENVDB_ABI_VERSION_NUMBER <= 3
668 Grid& operator=(
const Grid&) =
delete;
671 #if OPENVDB_ABI_VERSION_NUMBER <= 3
688 ConstPtr copy()
const;
690 Ptr copyWithNewTree()
const;
699 Ptr deepCopy()
const {
return Ptr(
new Grid(*
this)); }
705 Name type()
const override {
return this->gridType(); }
722 bool empty()
const override {
return tree().empty(); }
724 void clear()
override { tree().clear(); }
740 ConstAccessor getAccessor()
const {
return ConstAccessor(tree()); }
744 ConstUnsafeAccessor getConstUnsafeAccessor()
const {
return ConstUnsafeAccessor(tree()); }
755 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
761 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
767 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
774 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
777 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
786 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
795 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
798 void pruneGrid(
float tolerance = 0.0)
override;
800 #if OPENVDB_ABI_VERSION_NUMBER >= 3
828 template<
typename OtherTreeType>
843 template<
typename OtherTreeType>
856 template<
typename OtherTreeType>
865 CoordBBox evalActiveVoxelBoundingBox()
const override;
867 Coord evalActiveVoxelDim()
const override;
878 TreePtrType treePtr() {
return mTree; }
886 TreeType& tree() {
return *mTree; }
904 void newTree()
override;
912 void readTopology(std::istream&)
override;
915 void writeTopology(std::ostream&)
const override;
918 void readBuffers(std::istream&)
override;
919 #if OPENVDB_ABI_VERSION_NUMBER >= 3
920 void readBuffers(std::istream&,
const CoordBBox&)
override;
927 void readNonresidentBuffers()
const override;
929 void writeBuffers(std::ostream&)
const override;
933 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
938 static inline bool hasMultiPassIO();
952 <<
" might not be threadsafe on this platform");
977 template<
typename Gr
idType>
978 inline typename GridType::Ptr
981 return GridBase::grid<GridType>(grid);
993 template<
typename Gr
idType>
994 inline typename GridType::ConstPtr
997 return GridBase::constGrid<GridType>(grid);
1010 template<
typename Gr
idType>
1011 inline typename GridType::Ptr
1014 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
1015 return gridPtrCast<GridType>(grid->deepCopyGrid());
1019 template<
typename Gr
idType>
1020 inline typename GridType::Ptr
1023 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
1033 template<
typename _TreeType>
1065 template<
typename _TreeType>
1094 template<
typename _TreeType>
1135 template<
typename LeafNodeType>
1137 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1141 template<
typename RootNodeType>
1148 template<
typename TreeType>
1158 template<
typename Gr
idType>
1159 inline typename GridType::Ptr
1164 if (grid && grid->type() == GridType::gridType()) {
1165 return StaticPtrCast<GridType>(grid);
1167 return typename GridType::Ptr();
1171 template<
typename Gr
idType>
1172 inline typename GridType::ConstPtr
1175 return ConstPtrCast<const GridType>(
1176 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1180 template<
typename Gr
idType>
1181 inline typename GridType::ConstPtr
1184 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(grid));
1188 template<
typename Gr
idType>
1189 inline typename GridType::ConstPtr
1192 return ConstPtrCast<const GridType>(
1193 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1200 return ConstPtrCast<TreeBase>(this->constBaseTreePtr());
1215 template<
typename TreeT>
1221 template<
typename TreeT>
1227 template<
typename TreeT>
1234 template<
typename TreeT>
1242 template<
typename TreeT>
1243 template<
typename OtherTreeType>
1246 mTree(new
TreeType(other.constTree()))
1251 #if OPENVDB_ABI_VERSION_NUMBER <= 3
1252 template<
typename TreeT>
1259 template<
typename TreeT>
1268 template<
typename TreeT>
1277 template<
typename TreeT>
1286 template<
typename TreeT>
1290 return Ptr(
new Grid(background));
1295 template<
typename TreeT>
1304 template<
typename TreeT>
1315 #if OPENVDB_ABI_VERSION_NUMBER <= 3
1317 template<
typename TreeT>
1322 switch (treePolicy) {
1328 ret.reset(
new Grid(*
this));
1338 template<
typename TreeT>
1342 return this->copy(treePolicy);
1345 #else // if OPENVDB_ABI_VERSION_NUMBER > 3
1347 template<
typename TreeT>
1354 template<
typename TreeT>
1362 template<
typename TreeT>
1372 template<
typename TreeT>
1376 return this->copy();
1379 template<
typename TreeT>
1383 return this->copy();
1387 template<
typename TreeT>
1391 return this->copyWithNewTree();
1400 template<
typename TreeT>
1405 if (tree->type() != TreeType::treeType()) {
1407 + tree->type() +
" to a grid of type " + this->type());
1409 mTree = StaticPtrCast<TreeType>(tree);
1413 template<
typename TreeT>
1417 mTree.reset(
new TreeType(this->background()));
1424 template<
typename TreeT>
1428 tree().sparseFill(bbox, value, active);
1432 template<
typename TreeT>
1436 this->sparseFill(bbox, value, active);
1439 template<
typename TreeT>
1443 tree().denseFill(bbox, value, active);
1446 template<
typename TreeT>
1451 const auto value = zeroVal<ValueType>() + tolerance;
1453 this->tree().prune(static_cast<ValueType>(value));
1456 #if OPENVDB_ABI_VERSION_NUMBER >= 3
1457 template<
typename TreeT>
1466 template<
typename TreeT>
1470 tree().merge(other.
tree(), policy);
1474 template<
typename TreeT>
1475 template<
typename OtherTreeType>
1479 tree().topologyUnion(other.
tree());
1483 template<
typename TreeT>
1484 template<
typename OtherTreeType>
1488 tree().topologyIntersection(other.
tree());
1492 template<
typename TreeT>
1493 template<
typename OtherTreeType>
1497 tree().topologyDifference(other.
tree());
1504 template<
typename TreeT>
1508 tree().evalMinMax(minVal, maxVal);
1512 template<
typename TreeT>
1517 tree().evalActiveVoxelBoundingBox(bbox);
1522 template<
typename TreeT>
1527 const bool nonempty = tree().evalActiveVoxelDim(dim);
1528 return (nonempty ? dim :
Coord());
1538 template<
typename TreeT>
1542 tree().readTopology(is, saveFloatAsHalf());
1546 template<
typename TreeT>
1550 tree().writeTopology(os, saveFloatAsHalf());
1554 template<
typename TreeT>
1559 tree().readBuffers(is, saveFloatAsHalf());
1561 uint16_t numPasses = 1;
1562 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1565 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1566 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1567 meta->setPass(pass);
1568 tree().readBuffers(is, saveFloatAsHalf());
1574 #if OPENVDB_ABI_VERSION_NUMBER >= 3
1578 template<
typename TreeT>
1583 tree().readBuffers(is, bbox, saveFloatAsHalf());
1585 uint16_t numPasses = 1;
1586 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1589 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1590 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1591 meta->setPass(pass);
1592 tree().readBuffers(is, saveFloatAsHalf());
1601 template<
typename TreeT>
1605 tree().readNonresidentBuffers();
1611 template<
typename TreeT>
1615 if (!hasMultiPassIO()) {
1616 tree().writeBuffers(os, saveFloatAsHalf());
1621 uint16_t numPasses = 1;
1622 meta->setCountingPasses(
true);
1624 tree().writeBuffers(os, saveFloatAsHalf());
1625 numPasses = static_cast<uint16_t>(meta->pass());
1626 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1627 meta->setCountingPasses(
false);
1630 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1631 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1632 meta->setPass(pass);
1633 tree().writeBuffers(os, saveFloatAsHalf());
1640 template<
typename TreeT>
1648 template<
typename TreeT>
1652 tree().print(os, verboseLevel);
1654 if (metaCount() > 0) {
1655 os <<
"Additional metadata:" << std::endl;
1657 os <<
" " << it->first;
1659 const std::string value = it->second->str();
1660 if (!value.empty()) os <<
": " << value;
1666 os <<
"Transform:" << std::endl;
1667 transform().print(os,
" ");
1675 template<
typename Gr
idType>
1676 inline typename GridType::Ptr
1679 return GridType::create(background);
1683 template<
typename Gr
idType>
1684 inline typename GridType::Ptr
1687 return GridType::create();
1691 template<
typename TreePtrType>
1695 using TreeType =
typename TreePtrType::element_type;
1700 template<
typename Gr
idType>
1701 typename GridType::Ptr
1704 using ValueType =
typename GridType::ValueType;
1707 static_assert(std::is_floating_point<ValueType>::value,
1708 "level-set grids must be floating-point-valued");
1710 typename GridType::Ptr grid = GridType::create(
1711 static_cast<ValueType>(voxelSize * halfWidth));
1721 namespace internal {
1724 template<
typename OpT,
typename GridBaseT,
typename T,
typename ...Ts>
1725 struct GridApplyImpl {
static bool apply(GridBaseT&, OpT&) {
return false; } };
1729 template<
typename OpT,
typename GridBaseT,
typename GridT,
typename ...GridTs>
1730 struct GridApplyImpl<OpT, GridBaseT,
TypeList<GridT, GridTs...>>
1732 static bool apply(GridBaseT& grid, OpT& op)
1734 if (grid.template isType<GridT>()) {
1738 return GridApplyImpl<OpT, GridBaseT,
TypeList<GridTs...>>::apply(grid, op);
1745 template<
typename Gr
idTypeListT,
typename OpT>
1749 return internal::GridApplyImpl<OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1752 template<
typename Gr
idTypeListT,
typename OpT>
1756 return internal::GridApplyImpl<OpT, GridBase, GridTypeListT>::apply(*
this, op);
1762 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels....
Definition: Grid.h:729
static TreeType & tree(TreeType &t)
Definition: Grid.h:1112
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1039
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:979
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:529
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
GridNamePred(const Name &_name)
Definition: Grid.h:551
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:450
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:419
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:1374
SharedPtr< Grid > Ptr
Definition: Grid.h:592
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1279
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:606
Abstract base class for typed grids.
Definition: Grid.h:104
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1100
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:947
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
Definition: Grid.h:456
const math::Transform & transform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:427
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1117
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:370
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:609
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1059
SharedPtr< TreeBase > Ptr
Definition: Tree.h:65
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:375
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1468
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1105
~Grid() override
Definition: Grid.h:665
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:66
~GridBase() override
Definition: Grid.h:113
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:701
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1099
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:603
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:532
const TreeType & tree() const
Definition: Grid.h:891
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1076
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1036
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:1389
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:1603
static const char *const META_GRID_NAME
Definition: Grid.h:369
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1098
static TreeType & tree(TreeType &t)
Definition: Grid.h:1053
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:610
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:537
UnsafeAccessor getUnsafeAccessor()
Return an accessor that provides random read and write access to this grid's voxels....
Definition: Grid.h:738
ConstAccessor getConstAccessor() const
Definition: Grid.h:742
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:545
ValueOffCIter cbeginValueOff() const
Definition: Grid.h:764
Definition: ValueAccessor.h:220
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1081
VecType
Definition: Types.h:532
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1109
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:593
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:445
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:724
static TreeType & tree(TreeType &t)
Definition: Grid.h:1083
const TreeType & constTree() const
Definition: Grid.h:892
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1216
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:705
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:373
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1089
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1120
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:883
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:510
const math::Transform & constTransform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:428
static TreeType & tree(GridType &g)
Definition: Grid.h:1084
ValueAllCIter cbeginValueAll() const
Definition: Grid.h:770
_TreeType TreeType
Definition: Grid.h:1038
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:570
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:1364
typename _TreeType::ValueType ValueType
Definition: Grid.h:598
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:1747
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1650
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:540
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1055
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1057
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:190
typename TreeType::ValueType ValueType
Definition: Grid.h:1078
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:502
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:199
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:418
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1042
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:1021
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1613
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:534
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:204
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:890
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1524
_TreeType TreeType
Definition: Grid.h:1068
Definition: LeafBuffer.h:67
typename _TreeType::BuildType BuildType
Definition: Grid.h:599
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1077
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:1548
ConstTreePtrType treePtr() const
Definition: Grid.h:881
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:604
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1110
ConstTreePtrType constTreePtr() const
Definition: Grid.h:882
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1136
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:602
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1121
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:722
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1071
typename TreeType::ValueType ValueType
Definition: Grid.h:1048
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1556
Definition: Exceptions.h:92
ValueOnCIter beginValueOn() const
Definition: Grid.h:757
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:1702
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1049
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:377
_TreeType TreeType
Definition: Grid.h:595
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1088
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:1477
static const char *const META_GRID_CLASS
Definition: Grid.h:367
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:533
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
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:1441
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:528
static TreeType & tree(GridType &g)
Definition: Grid.h:1054
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1506
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:448
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:171
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1079
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1087
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1080
Name name
Definition: Grid.h:553
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:747
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1114
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers.
Definition: Grid.h:1642
Base class for typed trees.
Definition: Tree.h:62
tree::TreeBase TreeBase
Definition: Grid.h:53
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:454
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1108
static TreeType & tree(GridType &g)
Definition: Grid.h:1113
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1072
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:542
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:371
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:605
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:608
static const char *const META_VECTOR_TYPE
Definition: Grid.h:372
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:538
double Real
Definition: Types.h:67
Definition: Exceptions.h:91
uint64_t Index64
Definition: Types.h:60
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:549
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:527
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:52
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:707
Definition: version.h:221
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1448
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:271
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:596
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:209
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
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:1486
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1514
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:956
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:177
typename GridType::Ptr GridPtrType
Definition: Grid.h:1075
typename GridType::Ptr GridPtrType
Definition: Grid.h:1104
Vec3< double > Vec3d
Definition: Vec3.h:689
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1116
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:489
static const char *const META_GRID_CREATOR
Definition: Grid.h:368
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1085
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:597
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1060
Index64 memUsage() const override
Definition: Grid.h:871
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1415
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:535
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1070
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1056
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1118
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:719
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:530
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 ...
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:714
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Definition: Grid.h:1434
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:611
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:945
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform.
Definition: Grid.h:1205
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:487
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1041
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1058
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1677
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:125
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:601
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:165
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1101
typename std::remove_const< ToType >::type Type
Definition: Types.h:348
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1115
GridClass
Definition: Types.h:502
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:539
ValueOffCIter beginValueOff() const
Definition: Grid.h:763
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1402
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:1495
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:543
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1040
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1090
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1047
Ptr(*)() GridFactory
Definition: Grid.h:110
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1119
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:374
ValueOnCIter cbeginValueOn() const
Definition: Grid.h:758
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:376
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:552
A list of types (not necessarily unique)
Definition: Types.h:439
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Exceptions.h:40
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:452
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:995
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:499
ValueAllCIter beginValueAll() const
Definition: Grid.h:769
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1086
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:1540
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:1160
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:1198
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1459
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1051
std::string Name
Definition: Name.h:44
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1050
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1046
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Definition: Grid.h:1182
MergePolicy
Definition: Types.h:555
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1069
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:1426
typename TreeType::ValueType ValueType
Definition: Grid.h:1107
_TreeType TreeType
Definition: Grid.h:1097
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:108
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:620
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1106
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 GridType::Ptr GridPtrType
Definition: Grid.h:1045
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:863
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:1356
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:280
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:544
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1693