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>
70 Real voxelSize = 1.0,
Real halfWidth = LEVEL_SET_HALF_WIDTH);
83 using GridFactory =
Ptr (*)();
102 #if OPENVDB_ABI_VERSION_NUMBER >= 7
131 static bool isRegistered(
const Name &
type);
134 static void clearRegistry();
144 virtual Name valueType()
const = 0;
147 template<
typename Gr
idType>
148 bool isType()
const {
return (this->
type() == GridType::gridType()); }
155 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>
203 virtual void newTree() = 0;
208 virtual bool empty()
const = 0;
210 virtual void clear() = 0;
221 virtual void pruneGrid(
float tolerance = 0.0) = 0;
227 void clipGrid(
const BBoxd&);
233 virtual void clip(
const CoordBBox&) = 0;
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&);
282 bool saveFloatAsHalf()
const;
283 void setSaveFloatAsHalf(
bool);
294 void clearGridClass();
320 void clearVectorType();
340 bool isInWorldSpace()
const;
342 void setIsInWorldSpace(
bool);
368 virtual Index64 activeVoxelCount()
const = 0;
372 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
375 virtual Coord evalActiveVoxelDim()
const = 0;
378 virtual Index64 memUsage()
const = 0;
384 void addStatsMetadata();
450 virtual void readTopology(std::istream&) = 0;
453 virtual void writeTopology(std::ostream&)
const = 0;
456 virtual void readBuffers(std::istream&) = 0;
458 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
464 virtual void readNonresidentBuffers()
const = 0;
466 virtual void writeBuffers(std::ostream&)
const = 0;
474 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
483 #if OPENVDB_ABI_VERSION_NUMBER >= 7
496 static void registerGrid(
const Name&
type, GridFactory);
498 static void unregisterGrid(
const Name&
type);
539 template<
typename Gr
idPtrContainerT>
544 typename GridPtrContainerT::const_iterator it =
545 std::find_if(container.begin(), container.end(),
GridNamePred(name));
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>
571 class Grid:
public GridBase
601 template<
typename OtherValueType>
633 template<
typename OtherTreeType>
673 #if OPENVDB_ABI_VERSION_NUMBER >= 7
809 void pruneGrid(
float tolerance = 0.0)
override;
815 void clip(
const CoordBBox&)
override;
837 template<
typename OtherTreeType>
852 template<
typename OtherTreeType>
865 template<
typename OtherTreeType>
945 void readBuffers(std::istream&,
const CoordBBox&)
override;
956 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
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();
1067 template<
typename _TreeType>
1097 template<
typename _TreeType>
1126 template<
typename _TreeType>
1167 template<
typename LeafNodeType>
1173 template<
typename RootNodeType>
1180 template<
typename TreeType>
1189 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1194 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
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)));
1247 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
1255 template<
typename TreeT>
1261 template<
typename TreeT>
1267 template<
typename TreeT>
1270 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1274 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1275 template<
typename TreeT>
1280 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
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>
1473 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
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 this->tree().prune(static_cast<ValueType>(
value));
1523 template<
typename TreeT>
1530 template<
typename TreeT>
1534 tree().merge(other.tree(),
policy);
1538 template<
typename TreeT>
1539 template<
typename OtherTreeType>
1543 tree().topologyUnion(other.tree());
1547 template<
typename TreeT>
1548 template<
typename OtherTreeType>
1552 tree().topologyIntersection(other.tree());
1556 template<
typename TreeT>
1557 template<
typename OtherTreeType>
1561 tree().topologyDifference(other.tree());
1568 template<
typename TreeT>
1572 tree().evalMinMax(minVal, maxVal);
1576 template<
typename TreeT>
1581 tree().evalActiveVoxelBoundingBox(bbox);
1586 template<
typename TreeT>
1591 const bool nonempty = tree().evalActiveVoxelDim(dim);
1592 return (nonempty ? dim : Coord());
1602 template<
typename TreeT>
1606 tree().readTopology(is, saveFloatAsHalf());
1610 template<
typename TreeT>
1614 tree().writeTopology(os, saveFloatAsHalf());
1618 template<
typename TreeT>
1623 tree().readBuffers(is, saveFloatAsHalf());
1625 uint16_t numPasses = 1;
1626 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1629 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1630 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1631 meta->setPass(pass);
1632 tree().readBuffers(is, saveFloatAsHalf());
1640 template<
typename TreeT>
1645 tree().readBuffers(is, bbox, saveFloatAsHalf());
1647 uint16_t numPasses = 1;
1648 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1651 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1652 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1653 meta->setPass(pass);
1654 tree().readBuffers(is, saveFloatAsHalf());
1663 template<
typename TreeT>
1667 tree().readNonresidentBuffers();
1671 template<
typename TreeT>
1675 if (!hasMultiPassIO()) {
1676 tree().writeBuffers(os, saveFloatAsHalf());
1681 uint16_t numPasses = 1;
1682 meta->setCountingPasses(
true);
1684 tree().writeBuffers(os, saveFloatAsHalf());
1685 numPasses =
static_cast<uint16_t
>(meta->pass());
1686 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1687 meta->setCountingPasses(
false);
1690 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1691 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1692 meta->setPass(pass);
1693 tree().writeBuffers(os, saveFloatAsHalf());
1700 template<
typename TreeT>
1708 template<
typename TreeT>
1712 tree().print(os, verboseLevel);
1714 if (metaCount() > 0) {
1715 os <<
"Additional metadata:" << std::endl;
1717 os <<
" " << it->first;
1720 if (!value.empty()) os <<
": " << value;
1726 os <<
"Transform:" << std::endl;
1735 template<
typename Gr
idType>
1736 inline typename GridType::Ptr
1739 return GridType::create(background);
1743 template<
typename Gr
idType>
1744 inline typename GridType::Ptr
1747 return GridType::create();
1751 template<
typename TreePtrType>
1752 inline typename Grid<typename TreePtrType::element_type>::Ptr
1755 using TreeType =
typename TreePtrType::element_type;
1760 template<
typename Gr
idType>
1761 typename GridType::Ptr
1764 using ValueType =
typename GridType::ValueType;
1768 "level-set grids must be floating-point-valued");
1770 typename GridType::Ptr grid = GridType::create(
1771 static_cast<ValueType>(voxelSize * halfWidth));
1781 namespace internal {
1784 template<
typename OpT,
typename GridBaseT,
typename T,
typename ...Ts>
1785 struct GridApplyImpl {
static bool apply(GridBaseT&, OpT&) {
return false; } };
1789 template<
typename OpT,
typename GridBaseT,
typename GridT,
typename ...GridTs>
1790 struct GridApplyImpl<OpT, GridBaseT, TypeList<GridT, GridTs...>>
1792 static bool apply(GridBaseT& grid, OpT& op)
1794 if (grid.template isType<GridT>()) {
1798 return GridApplyImpl<OpT, GridBaseT, TypeList<GridTs...>>::apply(grid, op);
1805 template<
typename Gr
idTypeListT,
typename OpT>
1809 return internal::GridApplyImpl<OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1812 template<
typename Gr
idTypeListT,
typename OpT>
1816 return internal::GridApplyImpl<OpT, GridBase, GridTypeListT>::apply(*
this, op);
1819 template<
typename Gr
idTypeListT,
typename OpT>
1823 return internal::GridApplyImpl<const OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1826 template<
typename Gr
idTypeListT,
typename OpT>
1830 return internal::GridApplyImpl<const OpT, GridBase, GridTypeListT>::apply(*
this, op);
1836 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
SharedPtr< T > StaticPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that points to the same object as the given pointer after a static_cast...
typename _TreeType::ValueType ValueType
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
typename tree::ValueAccessor< const TreeType > ConstAccessorType
typename tree::ValueAccessor< TreeType > AccessorType
static const TreeType & tree(const TreeType &t)
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
GridPtrSet::iterator GridPtrSetIter
OPENVDB_API void setGridClass(std::ios_base &, uint32_t)
Associate with the given stream the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently ...
SharedPtr< TreeBase > Ptr
typename TreeType::ConstPtr ConstTreePtrType
static TreeType & tree(GridType &g)
typename NonConstTreeType::Ptr NonConstTreePtrType
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
static const TreeType & constTree(const TreeType &t)
#define OPENVDB_LOG_WARN(mesg)
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
GLuint const GLchar * name
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
SharedPtr< GridBase > Ptr
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
hboost::math::policies::policy< hboost::math::policies::domain_error< hboost::math::policies::ignore_error >, hboost::math::policies::pole_error< hboost::math::policies::ignore_error >, hboost::math::policies::overflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::underflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::denorm_error< hboost::math::policies::ignore_error >, hboost::math::policies::rounding_error< hboost::math::policies::ignore_error >, hboost::math::policies::evaluation_error< hboost::math::policies::ignore_error >, hboost::math::policies::indeterminate_result_error< hboost::math::policies::ignore_error > > policy
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
SharedPtr< const Grid > ConstPtr
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
void topologyIntersection(const Grid< OtherTreeType > &other)
Intersect this grid's set of active values with the active values of the other grid, whose value type may be different.
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
void readTransform(std::istream &is)
Read in the transform for this grid.
Grid & operator=(const Grid &)=delete
Disallow assignment, since it wouldn't be obvious whether the copy is deep or shallow.
static const char *const META_GRID_NAME
typename tree::ValueAccessor< TreeType > AccessorType
ConstPtr copyReplacingMetadata(const MetaMap &meta) const
Return a new grid of the same type as this grid whose tree and transform is shared with this grid and...
GLuint GLenum GLenum transform
typename TreeType::ConstPtr ConstTreePtrType
static const TreeType & constTree(TreeType &t)
static const TreeType & constTree(GridType &g)
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Mat3< Type1 > cwiseAdd(const Mat3< Type1 > &m, const Type2 s)
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
typename _TreeType::ValueOffCIter ValueOffCIter
GLboolean GLboolean GLboolean GLboolean a
SharedPtr< GridCPtrVec > GridCPtrVecPtr
SharedPtr< GridPtrSet > GridPtrSetPtr
static const TreeType & constTree(const GridType &g)
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Ptr copyWithNewTree() const
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
static const char *const META_SAVE_HALF_FLOAT
void topologyDifference(const Grid< OtherTreeType > &other)
Difference this grid's set of active values with the active values of the other grid, whose value type may be different.
TreePtrType treePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
typename TreeType::ValueType ValueType
typename tree::ValueAccessor< const TreeType > ConstAccessorType
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
SharedPtr< GridCPtrSet > GridCPtrSetPtr
#define OPENVDB_USE_VERSION_NAMESPACE
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
GridCPtrSet::const_iterator GridCPtrSetCIter
bool operator()(const GridBase::ConstPtr &g) const
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
static const char *const META_FILE_COMPRESSION
static const char *const META_IS_LOCAL_SPACE
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
typename NonConstGridType::Ptr NonConstGridPtrType
static const char *const META_GRID_CLASS
static TreeType & tree(GridType &g)
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Ptr copy()
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
typename TreeType::ValueType ValueType
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
ConstPtr copyReplacingTransform(math::Transform::Ptr xform) const
Return a new grid of the same type as this grid whose tree is shared with this grid, whose metadata is a deep copy of this grid's and whose transform is provided as an argument.
TreeBase::Ptr baseTreePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
std::vector< GridBase::Ptr > GridPtrVec
typename std::remove_const< TreeType >::type NonConstTreeType
std::set< GridBase::Ptr > GridPtrSet
typename _TreeType::ConstPtr ConstTreePtrType
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
GridBase::ConstPtr copyGridReplacingTransform(math::Transform::Ptr xform) const override
Return a new grid of the same type as this grid whose tree is shared with this grid, whose metadata is a deep copy of this grid's and whose transform is provided as an argument.
GridBase::Ptr copyGrid() override
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
GridCPtrSet::iterator GridCPtrSetIter
static const char *const META_FILE_VOXEL_COUNT
static TreeType & tree(AccessorType &a)
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
std::shared_ptr< T > SharedPtr
static const TreeType & constTree(const TreeType &t)
static const TreeType & tree(const GridType &g)
Abstract base class for typed grids.
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
static const char *const META_FILE_BBOX_MIN
typename std::remove_const< TreeType >::type NonConstTreeType
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
bool isType() const
Return true if this grid is of the same type as the template parameter.
GridBase::ConstPtr copyGridReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const override
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
void writeTopology(std::ostream &) const override
Write the grid topology to a stream. This will write only the grid structure, not the actual data buf...
static TreeType & tree(TreeType &t)
static void unregisterGrid()
Remove this grid type from the registry.
typename _TreeType::ValueAllCIter ValueAllCIter
static Ptr create()
Return a new grid with background value zero.
static void registerGrid()
Register this grid type along with a factory function.
GridType::Ptr createLevelSet(Real voxelSize=1.0, Real halfWidth=LEVEL_SET_HALF_WIDTH)
Create a new grid of type GridType classified as a "Level Set", i.e., a narrow-band level set...
GridBase(GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
static const TreeType & tree(const GridType &g)
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
GridBase::Ptr copyGridWithNewTree() const override
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
void sparseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
ConstTreePtrType treePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
typename GridType::ConstPtr ConstGridPtrType
bool apply(OpT &) const
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid...
typename std::remove_const< ToType >::type Type
typename GridType::Ptr GridPtrType
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
typename _TreeType::ValueOffIter ValueOffIter
typename NonConstGridType::Ptr NonConstGridPtrType
Name type() const override
Return the name of this grid's type.
Index64 memUsage() const override
static TreeType & tree(TreeType &t)
GridType::Ptr gridPtrCast(const GridBase::Ptr &grid)
Cast a generic grid pointer to a pointer to a grid of a concrete class.
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
typename TreeType::ConstPtr ConstTreePtrType
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
static TreeType & tree(TreeType &t)
GridNamePred(const Name &_name)
GridBase()
Initialize with an identity linear transform.
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
typename TreeType::Ptr TreePtrType
math::Transform::Ptr transformPtr()
Return a pointer to this grid's transform, which might be shared with other grids.
typename GridType::Ptr GridPtrType
GLuint GLuint GLsizei GLenum type
TreeBase::ConstPtr baseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Container class that associates a tree with a transform and metadata.
ConstTreePtrType constTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
void topologyUnion(const Grid< OtherTreeType > &other)
Union this grid's set of active values with the active values of the other grid, whose value type may...
SharedPtr< GridPtrVec > GridPtrVecPtr
typename _TreeType::ValueOnIter ValueOnIter
void readNonresidentBuffers() const override
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
GridPtrSet::const_iterator GridPtrSetCIter
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
static GridType::Ptr grid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
const ValueType & background() const
Return this grid's background value.
static const TreeType & constTree(GridType &g)
Base class for typed trees.
static const TreeType & tree(const TreeType &t)
GridType::Ptr deepCopyTypedGrid(const GridBase::ConstPtr &grid)
Return a pointer to a deep copy of the given grid, provided that the grid's concrete type is GridType...
typename std::remove_const< TreeType >::type NonConstTreeType
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
Predicate functor that returns true for grids that have a specified name.
GridCPtrVec::iterator GridCPtrVecIter
GLsizei const GLchar *const * string
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
ConstPtr copyReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
static const char *const META_FILE_MEM_BYTES
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...
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T clip(const T &p, const Box< T > &box)
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
GridBase::ConstPtr copyGridReplacingMetadata(const MetaMap &meta) const override
Return a new grid of the same type as this grid whose tree and transform is shared with this grid and...
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
static const TreeType & tree(const AccessorType &a)
typename GridType::Ptr GridPtrType
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
static const TreeType & constTree(const GridType &g)
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 tree::ValueAccessor< _TreeType, true > Accessor
typename _TreeType::ValueOnCIter ValueOnCIter
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
GridPtrVec::iterator GridPtrVecIter
typename TreeType::ValueType ValueType
static const char *const META_FILE_DELAYED_LOAD
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
static const TreeType & constTree(const TreeType &t)
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
typename NonConstGridType::Ptr NonConstGridPtrType
SharedPtr< const GridBase > ConstPtr
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
OIIO_API bool copy(string_view from, string_view to, std::string &err)
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels...
SharedPtr< const TreeBase > ConstPtr
static const char *const META_GRID_CREATOR
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
GridType::ConstPtr gridConstPtrCast(const GridBase::ConstPtr &grid)
Cast a generic const grid pointer to a const pointer to a grid of a concrete class.
typename GridType::ConstPtr ConstGridPtrType
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
typename TreeType::Ptr TreePtrType
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Vec3d voxelSize() const
Return the size of this grid's voxels.
static const TreeType & tree(const GridType &g)
static bool isRegistered()
Return true if this grid type is registered.
bool empty() const override
Return true if this grid contains only inactive background voxels.
static const TreeType & constTree(const GridType &g)
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
GridPtrContainerT::value_type findGridByName(const GridPtrContainerT &container, const Name &name)
Return the first grid in the given container whose name is name.
typename _TreeType::BuildType BuildType
typename NonConstTreeType::Ptr NonConstTreePtrType
static const char *const META_VECTOR_TYPE
virtual TreeBase::ConstPtr constBaseTreePtr() const =0
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
static const TreeType & constTree(TreeType &t)
Grid()
Construct a new grid with background value zero.
void readBuffers(std::istream &) override
Read all data buffers for this grid.
static const TreeType & tree(const TreeType &t)
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
bool isTreeUnique() const
Return true if tree is not shared with another grid.
typename TreeType::Ptr TreePtrType
std::set< GridBase::ConstPtr > GridCPtrSet
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
std::vector< GridBase::ConstPtr > GridCPtrVec
typename _TreeType::ValueAllIter ValueAllIter
static const TreeType & constTree(TreeType &t)
static const TreeType & constTree(GridType &g)
static Name gridType()
Return the name of this type of grid.
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
GLsizei const GLfloat * value
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
TreeBase::ConstPtr constBaseTreePtr() const override
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
void readTopology(std::istream &) override
Read the grid topology from a stream. This will read only the grid structure, not the actual data buf...
GridCPtrVec::const_iterator GridCPtrVecCIter
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
static TreeType & tree(GridType &g)
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
typename tree::ValueAccessor< TreeType > AccessorType
static const char *const META_FILE_BBOX_MAX
GridPtrVec::const_iterator GridPtrVecCIter
#define OPENVDB_THROW(exception, message)
typename GridType::ConstPtr ConstGridPtrType
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
typename NonConstTreeType::Ptr NonConstTreePtrType
typename _TreeType::Ptr TreePtrType
Index64 activeVoxelCount() const override
Return the number of active voxels.
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
std::enable_if< internal::is_string< S >::value >::type print(std::basic_ostream< FMT_CHAR(S)> &os, const S &format_str, const Args &...args)
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.