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>
115 #if OPENVDB_ABI_VERSION_NUMBER <= 3
116 virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE)
const = 0;
156 template<
typename Gr
idType>
157 bool isType()
const {
return (this->type() == GridType::gridType()); }
160 template<
typename Gr
idType>
164 template<
typename Gr
idType>
166 template<
typename Gr
idType>
167 static typename GridType::ConstPtr constGrid(
const GridBase::Ptr&);
168 template<
typename Gr
idType>
181 TreeBase& baseTree() {
return const_cast<TreeBase&
>(this->constBaseTree()); }
212 #if OPENVDB_ABI_VERSION_NUMBER >= 3
213 void clipGrid(
const BBoxd&);
366 Vec3d indexToWorld(
const Vec3d& xyz)
const {
return transform().indexToWorld(xyz); }
370 Vec3d worldToIndex(
const Vec3d& xyz)
const {
return transform().worldToIndex(xyz); }
386 #if OPENVDB_ABI_VERSION_NUMBER >= 3
387 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
396 virtual void writeBuffers(std::ostream&)
const = 0;
405 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
410 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
415 #if OPENVDB_ABI_VERSION_NUMBER <= 3
467 template<
typename Gr
idPtrContainerT>
468 inline typename GridPtrContainerT::value_type
471 using GridPtrT =
typename GridPtrContainerT::value_type;
472 typename GridPtrContainerT::const_iterator it =
473 std::find_if(container.begin(), container.end(),
GridNamePred(name));
474 return (it == container.end() ? GridPtrT() : *it);
478 template<
typename KeyT,
typename Gr
idPtrT>
482 using GridPtrMapT = std::map<KeyT, GridPtrT>;
483 for (
typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
486 const GridPtrT& grid = it->second;
487 if (grid && grid->getName() == name)
return grid;
498 template<
typename _TreeType>
529 template<
typename OtherValueType>
561 template<
typename OtherTreeType>
563 #if OPENVDB_ABI_VERSION_NUMBER <= 3
580 #if OPENVDB_ABI_VERSION_NUMBER <= 3
582 Ptr copy(CopyPolicy treePolicy = CP_SHARE)
const;
589 GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE)
const override;
598 Ptr copyWithNewTree()
const;
607 Ptr deepCopy()
const {
return Ptr(
new Grid(*
this)); }
613 Name type()
const override {
return this->gridType(); }
630 bool empty()
const override {
return tree().empty(); }
632 void clear()
override { tree().clear(); }
648 ConstAccessor getAccessor()
const {
return ConstAccessor(tree()); }
652 ConstUnsafeAccessor getConstUnsafeAccessor()
const {
return ConstUnsafeAccessor(tree()); }
663 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
669 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
675 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
682 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
685 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
694 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
703 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
706 void pruneGrid(
float tolerance = 0.0)
override;
708 #if OPENVDB_ABI_VERSION_NUMBER >= 3
736 template<
typename OtherTreeType>
751 template<
typename OtherTreeType>
764 template<
typename OtherTreeType>
773 CoordBBox evalActiveVoxelBoundingBox()
const override;
775 Coord evalActiveVoxelDim()
const override;
786 TreePtrType treePtr() {
return mTree; }
794 TreeType& tree() {
return *mTree; }
812 void newTree()
override;
820 void readTopology(std::istream&)
override;
823 void writeTopology(std::ostream&)
const override;
826 void readBuffers(std::istream&)
override;
827 #if OPENVDB_ABI_VERSION_NUMBER >= 3
828 void readBuffers(std::istream&,
const CoordBBox&)
override;
835 void readNonresidentBuffers()
const override;
837 void writeBuffers(std::ostream&)
const override;
841 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
846 static inline bool hasMultiPassIO();
860 <<
" might not be threadsafe on this platform");
885 template<
typename Gr
idType>
886 inline typename GridType::Ptr
889 return GridBase::grid<GridType>(grid);
901 template<
typename Gr
idType>
902 inline typename GridType::ConstPtr
905 return GridBase::constGrid<GridType>(grid);
918 template<
typename Gr
idType>
919 inline typename GridType::Ptr
922 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
923 return gridPtrCast<GridType>(grid->deepCopyGrid());
927 template<
typename Gr
idType>
928 inline typename GridType::Ptr
931 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
941 template<
typename _TreeType>
973 template<
typename _TreeType>
1002 template<
typename _TreeType>
1043 template<
typename LeafNodeType>
1045 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1049 template<
typename RootNodeType>
1056 template<
typename TreeType>
1066 template<
typename Gr
idType>
1067 inline typename GridType::Ptr
1072 if (grid && grid->type() == GridType::gridType()) {
1073 return StaticPtrCast<GridType>(grid);
1075 return typename GridType::Ptr();
1079 template<
typename Gr
idType>
1080 inline typename GridType::ConstPtr
1083 return ConstPtrCast<const GridType>(
1084 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1088 template<
typename Gr
idType>
1089 inline typename GridType::ConstPtr
1092 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(grid));
1096 template<
typename Gr
idType>
1097 inline typename GridType::ConstPtr
1100 return ConstPtrCast<const GridType>(
1101 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1108 return ConstPtrCast<TreeBase>(this->constBaseTreePtr());
1123 template<
typename TreeT>
1129 template<
typename TreeT>
1135 template<
typename TreeT>
1142 template<
typename TreeT>
1150 template<
typename TreeT>
1151 template<
typename OtherTreeType>
1154 mTree(new
TreeType(other.constTree()))
1159 #if OPENVDB_ABI_VERSION_NUMBER <= 3
1160 template<
typename TreeT>
1167 template<
typename TreeT>
1176 template<
typename TreeT>
1185 template<
typename TreeT>
1194 template<
typename TreeT>
1198 return Ptr(
new Grid(background));
1203 template<
typename TreeT>
1212 template<
typename TreeT>
1223 #if OPENVDB_ABI_VERSION_NUMBER <= 3
1225 template<
typename TreeT>
1230 switch (treePolicy) {
1236 ret.reset(
new Grid(*
this));
1246 template<
typename TreeT>
1250 return this->copy(treePolicy);
1253 #else // if OPENVDB_ABI_VERSION_NUMBER > 3
1255 template<
typename TreeT>
1262 template<
typename TreeT>
1270 template<
typename TreeT>
1280 template<
typename TreeT>
1284 return this->copy();
1287 template<
typename TreeT>
1291 return this->copy();
1295 template<
typename TreeT>
1299 return this->copyWithNewTree();
1308 template<
typename TreeT>
1313 if (tree->type() != TreeType::treeType()) {
1315 + tree->type() +
" to a grid of type " + this->type());
1317 mTree = StaticPtrCast<TreeType>(tree);
1321 template<
typename TreeT>
1325 mTree.reset(
new TreeType(this->background()));
1332 template<
typename TreeT>
1336 tree().sparseFill(bbox, value, active);
1340 template<
typename TreeT>
1344 this->sparseFill(bbox, value, active);
1347 template<
typename TreeT>
1351 tree().denseFill(bbox, value, active);
1354 template<
typename TreeT>
1358 this->tree().prune(
ValueType(zeroVal<ValueType>() + tolerance));
1361 #if OPENVDB_ABI_VERSION_NUMBER >= 3
1362 template<
typename TreeT>
1371 template<
typename TreeT>
1375 tree().merge(other.
tree(), policy);
1379 template<
typename TreeT>
1380 template<
typename OtherTreeType>
1384 tree().topologyUnion(other.
tree());
1388 template<
typename TreeT>
1389 template<
typename OtherTreeType>
1393 tree().topologyIntersection(other.
tree());
1397 template<
typename TreeT>
1398 template<
typename OtherTreeType>
1402 tree().topologyDifference(other.
tree());
1409 template<
typename TreeT>
1413 tree().evalMinMax(minVal, maxVal);
1417 template<
typename TreeT>
1422 tree().evalActiveVoxelBoundingBox(bbox);
1427 template<
typename TreeT>
1432 const bool nonempty = tree().evalActiveVoxelDim(dim);
1433 return (nonempty ? dim :
Coord());
1443 template<
typename TreeT>
1447 tree().readTopology(is, saveFloatAsHalf());
1451 template<
typename TreeT>
1455 tree().writeTopology(os, saveFloatAsHalf());
1459 template<
typename TreeT>
1464 tree().readBuffers(is, saveFloatAsHalf());
1466 uint16_t numPasses = 1;
1467 is.read(
reinterpret_cast<char*
>(&numPasses),
sizeof(uint16_t));
1470 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1471 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1472 meta->setPass(pass);
1473 tree().readBuffers(is, saveFloatAsHalf());
1479 #if OPENVDB_ABI_VERSION_NUMBER >= 3
1483 template<
typename TreeT>
1488 tree().readBuffers(is, bbox, saveFloatAsHalf());
1490 uint16_t numPasses = 1;
1491 is.read(
reinterpret_cast<char*
>(&numPasses),
sizeof(uint16_t));
1494 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1495 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1496 meta->setPass(pass);
1497 tree().readBuffers(is, saveFloatAsHalf());
1506 template<
typename TreeT>
1510 tree().readNonresidentBuffers();
1516 template<
typename TreeT>
1520 if (!hasMultiPassIO()) {
1521 tree().writeBuffers(os, saveFloatAsHalf());
1526 uint16_t numPasses = 1;
1527 meta->setCountingPasses(
true);
1529 tree().writeBuffers(os, saveFloatAsHalf());
1530 numPasses =
static_cast<uint16_t
>(meta->pass());
1531 os.write(
reinterpret_cast<const char*
>(&numPasses),
sizeof(uint16_t));
1532 meta->setCountingPasses(
false);
1535 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1536 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1537 meta->setPass(pass);
1538 tree().writeBuffers(os, saveFloatAsHalf());
1545 template<
typename TreeT>
1553 template<
typename TreeT>
1557 tree().print(os, verboseLevel);
1559 if (metaCount() > 0) {
1560 os <<
"Additional metadata:" << std::endl;
1561 for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1562 os <<
" " << it->first;
1564 const std::string value = it->second->str();
1565 if (!value.empty()) os <<
": " << value;
1571 os <<
"Transform:" << std::endl;
1572 transform().print(os,
" ");
1580 template<
typename Gr
idType>
1581 inline typename GridType::Ptr
1584 return GridType::create(background);
1588 template<
typename Gr
idType>
1589 inline typename GridType::Ptr
1592 return GridType::create();
1596 template<
typename TreePtrType>
1600 using TreeType =
typename TreePtrType::element_type;
1605 template<
typename Gr
idType>
1606 typename GridType::Ptr
1609 using ValueType =
typename GridType::ValueType;
1612 static_assert(std::is_floating_point<ValueType>::value,
1613 "level-set grids must be floating-point-valued");
1615 typename GridType::Ptr grid = GridType::create(
1616 static_cast<ValueType
>(voxelSize * halfWidth));
1625 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
GridBase::Ptr copyGridWithNewTree() const override
Definition: Grid.h:1297
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:1508
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:511
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:613
Index64 memUsage() const override
Definition: Grid.h:779
typename TreeType::ValueType ValueType
Definition: Grid.h:986
virtual TreeBase::ConstPtr constBaseTreePtr() const =0
virtual Coord evalActiveVoxelDim() const =0
Return the dimensions of the axis-aligned bounding box of all active voxels.
virtual Index64 activeVoxelCount() const =0
Return the number of active voxels.
virtual GridBase::ConstPtr copyGrid() const =0
static void clearRegistry()
Clear the grid type registry.
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
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
VecType
Definition: Types.h:305
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:462
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:947
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
Vec3d indexToWorld(const Coord &ijk) const
Definition: Grid.h:368
_TreeType TreeType
Definition: Grid.h:946
static const TreeType & tree(const GridType &g)
Definition: Grid.h:994
const TreeBase & constBaseTree() const
Definition: Grid.h:187
void setSaveFloatAsHalf(bool)
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1429
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:52
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1022
ValueOnCIter cbeginValueOn() const
Definition: Grid.h:666
void setVectorType(VecType)
Specify the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this ...
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:453
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.) stored in this grid.
double Real
Definition: Types.h:67
GridNamePred(const Name &_name)
Definition: Grid.h:461
Grid & operator=(const Grid &)=delete
Disallow assignment, since it wouldn't be obvious whether the copy is deep or shallow.
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:945
ValueOffCIter beginValueOff() const
Definition: Grid.h:671
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1310
ValueAllCIter beginValueAll() const
Definition: Grid.h:677
TreeBase::ConstPtr baseTreePtr() const
Definition: Grid.h:176
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1518
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:480
ValueOnCIter beginValueOn() const
Definition: Grid.h:665
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:995
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:157
typename GridType::Ptr GridPtrType
Definition: Grid.h:1012
Definition: ValueAccessor.h:221
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:512
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:984
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:958
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:1607
virtual void pruneGrid(float tolerance=0.0)=0
Reduce the memory footprint of this grid by increasing its sparseness either losslessly (tolerance = ...
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:66
virtual Name valueType() const =0
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1555
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:955
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:514
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:439
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1018
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:516
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:444
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:1382
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1024
typename _TreeType::BuildType BuildType
Definition: Grid.h:509
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:771
static const TreeType & tree(const GridType &g)
Definition: Grid.h:964
ConstTreePtrType treePtr() const
Definition: Grid.h:789
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
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:1349
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels....
Definition: Grid.h:637
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1008
static const char *const META_VECTOR_TYPE
Definition: Grid.h:296
typename TreeType::Ptr TreePtrType
Definition: Grid.h:948
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1014
virtual CoordBBox evalActiveVoxelBoundingBox() const =0
SharedPtr< TreeBase > Ptr
Definition: Tree.h:65
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1411
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:993
Ptr(*)() GridFactory
Definition: Grid.h:110
@ GRID_LEVEL_SET
Definition: Types.h:277
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:518
static VecType stringToVecType(const std::string &)
Definition: LeafBuffer.h:68
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:300
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:460
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform.
Definition: Grid.h:1113
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:400
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:500
void setCreator(const std::string &)
Provide a description of this grid's creator.
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:452
MetaMap::Ptr getStatsMetadata() const
Return a new MetaMap containing just the metadata that was added to this grid with addStatsMetadata()...
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1029
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:519
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...
typename TreeType::Ptr TreePtrType
Definition: Grid.h:978
static std::string gridClassToMenuName(GridClass)
Return a formatted string version of the grid class.
bool isInWorldSpace() const
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:445
typename TreeType::ValueType ValueType
Definition: Grid.h:1015
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:515
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers.
Definition: Grid.h:1547
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:364
MergePolicy
Definition: Types.h:328
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:959
_TreeType TreeType
Definition: Grid.h:976
virtual Index64 memUsage() const =0
Return the number of bytes of memory used by this grid.
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:977
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:402
const TreeType & tree() const
Definition: Grid.h:799
Name name
Definition: Grid.h:463
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:515
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:455
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:632
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1017
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:442
static TreeType & tree(TreeType &t)
Definition: Grid.h:961
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1373
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1124
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1006
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
TreeBase::ConstPtr constBaseTreePtr() const override
Definition: Grid.h:791
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:1068
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1027
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:530
ValueAllCIter cbeginValueAll() const
Definition: Grid.h:678
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:1106
Abstract base class for typed grids.
Definition: Grid.h:105
Definition: Exceptions.h:91
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Definition: Grid.h:1090
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:627
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:108
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:507
static const char *const META_GRID_CREATOR
Definition: Grid.h:292
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:622
ValueOffCIter cbeginValueOff() const
Definition: Grid.h:672
const math::Transform & transform() const
Definition: Grid.h:348
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Definition: Grid.h:1342
static TreeType & tree(TreeType &t)
Definition: Grid.h:1020
virtual void newTree()=0
Set a new tree with the same background value as the previous tree.
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:798
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:1272
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:521
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:853
void setIsInWorldSpace(bool)
Specify whether this grid's voxel values are in world space or in local space.
static TreeType & tree(TreeType &t)
Definition: Grid.h:991
ConstTreePtrType constTreePtr() const
Definition: Grid.h:790
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:503
math::Transform::ConstPtr constTransformPtr() const
Definition: Grid.h:340
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1013
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1323
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:630
virtual void clip(const CoordBBox &)=0
Clip this grid to the given index-space bounding box.
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...
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:989
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:987
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1025
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:298
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:1400
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:449
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:448
static const TreeType & constTree(GridType &g)
Definition: Grid.h:966
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:450
_TreeType TreeType
Definition: Grid.h:505
static const TreeType & constTree(GridType &g)
Definition: Grid.h:996
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:903
GridClass
Definition: Types.h:275
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:410
typename _TreeType::ValueType ValueType
Definition: Grid.h:508
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1582
virtual void setTree(TreeBase::Ptr)=0
Associate the given tree with this grid, in place of its existing tree.
_TreeType TreeType
Definition: Grid.h:1005
virtual void clear()=0
Empty this grid, setting all voxels to the background.
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:965
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1044
typename TreeType::ValueType ValueType
Definition: Grid.h:956
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1598
@ MERGE_ACTIVE_STATES
Definition: Types.h:329
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.
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:1453
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:967
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:294
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
const math::Transform & constTransform() const
Definition: Grid.h:349
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:985
typename GridType::Ptr GridPtrType
Definition: Grid.h:983
std::string getCreator() const
Return the user-specified description of this grid's creator.
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1364
Vec3< double > Vec3d
Definition: Vec3.h:679
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1461
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:929
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1016
~GridBase() override
Definition: Grid.h:113
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:1445
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1007
virtual bool empty() const =0
Return true if this grid contains only background voxels.
typename GridType::Ptr GridPtrType
Definition: Grid.h:953
static const char *const META_GRID_NAME
Definition: Grid.h:293
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:949
static std::string vecTypeToString(VecType)
Return the metadata string value for the given type of vector data.
uint64_t Index64
Definition: Types.h:60
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:1264
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:297
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:265
SharedPtr< Grid > Ptr
Definition: Grid.h:502
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:1334
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:968
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:980
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:855
tree::TreeBase TreeBase
Definition: Grid.h:53
Definition: Exceptions.h:92
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1028
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:440
static std::string vecTypeExamples(VecType)
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:295
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:615
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:997
void addStatsMetadata()
Add metadata to this grid comprising the current values of statistics like the active voxel count and...
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:283
static TreeType & tree(GridType &g)
Definition: Grid.h:962
void clearGridClass()
Remove the setting specifying the class of this grid's volumetric data.
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1356
~Grid() override
Definition: Grid.h:574
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
std::string Name
Definition: Name.h:44
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1187
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:954
GridBase::Ptr deepCopyGrid() const override
Definition: Grid.h:609
void setName(const std::string &)
Specify a name for this grid.
@ OPENVDB_FILE_VERSION_MULTIPASS_IO
Definition: version.h:232
void clearVectorType()
Remove the setting specifying the type of vector data stored in this grid.
static TreeType & tree(GridType &g)
Definition: Grid.h:1021
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:1391
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:988
const TreeBase & baseTree() const
Definition: Grid.h:186
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:957
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1023
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:864
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:520
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:887
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
static GridClass stringToGridClass(const std::string &)
Return the class of volumetric data specified by the given string.
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:454
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:447
void setGridClass(GridClass)
Specify the class of volumetric data (level set, fog volume, etc.) stored in this grid.
static std::string vecTypeDescription(VecType)
Return a string describing how the given type of vector data is affected by transformations (e....
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:506
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:299
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
UnsafeAccessor getUnsafeAccessor()
Return an accessor that provides random read and write access to this grid's voxels....
Definition: Grid.h:646
Base class for typed trees.
Definition: Tree.h:63
GridBase::Ptr copyGrid() override
Definition: Grid.h:1282
Definition: Exceptions.h:40
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:963
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:437
static std::string gridClassToString(GridClass)
Return the metadata string value for the given class of volumetric data.
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1026
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:359
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:950
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:362
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:413
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1009
math::Transform::ConstPtr transformPtr() const
Definition: Grid.h:339
ConstAccessor getConstAccessor() const
Definition: Grid.h:650
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:301
virtual void readBuffers(std::istream &)=0
Read all data buffers for this grid.
std::string getName() const
Return this grid's user-specified name.
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1419
const TreeType & constTree() const
Definition: Grid.h:800
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:998
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:443
static const char *const META_GRID_CLASS
Definition: Grid.h:291
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
VecType getVectorType() const
Return the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this g...
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:438
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:513
static TreeType & tree(GridType &g)
Definition: Grid.h:992
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:979
virtual Name type() const =0
Return the name of this grid's type.
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:280