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>
178 #if OPENVDB_ABI_VERSION_NUMBER >= 8
180 virtual bool isTreeUnique()
const = 0;
208 virtual void newTree() = 0;
213 virtual bool empty()
const = 0;
215 virtual void clear() = 0;
226 virtual void pruneGrid(
float tolerance = 0.0) = 0;
232 void clipGrid(
const BBoxd&);
238 virtual void clip(
const CoordBBox&) = 0;
266 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&)
const;
267 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&);
268 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&)
const;
269 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&);
287 bool saveFloatAsHalf()
const;
288 void setSaveFloatAsHalf(
bool);
299 void clearGridClass();
325 void clearVectorType();
345 bool isInWorldSpace()
const;
347 void setIsInWorldSpace(
bool);
373 virtual Index64 activeVoxelCount()
const = 0;
377 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
380 virtual Coord evalActiveVoxelDim()
const = 0;
389 void addStatsMetadata();
455 virtual void readTopology(std::istream&) = 0;
458 virtual void writeTopology(std::ostream&)
const = 0;
461 virtual void readBuffers(std::istream&) = 0;
463 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
469 virtual void readNonresidentBuffers()
const = 0;
471 virtual void writeBuffers(std::ostream&)
const = 0;
479 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
486 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
488 #if OPENVDB_ABI_VERSION_NUMBER >= 7
501 static void registerGrid(
const Name&
type, GridFactory);
503 static void unregisterGrid(
const Name&
type);
544 template<
typename Gr
idPtrContainerT>
549 typename GridPtrContainerT::const_iterator it =
550 std::find_if(container.begin(), container.end(),
GridNamePred(name));
551 return (it == container.end() ? GridPtrT() : *it);
555 template<
typename KeyT,
typename Gr
idPtrT>
559 using GridPtrMapT = std::map<KeyT, GridPtrT>;
560 for (
typename GridPtrMapT::const_iterator it = container.begin(),
end = container.end();
563 const GridPtrT& grid = it->second;
564 if (grid && grid->getName() == name)
return grid;
575 template<
typename _TreeType>
576 class Grid:
public GridBase
606 template<
typename OtherValueType>
638 template<
typename OtherTreeType>
678 #if OPENVDB_ABI_VERSION_NUMBER >= 7
814 void pruneGrid(
float tolerance = 0.0)
override;
820 void clip(
const CoordBBox&)
override;
842 template<
typename OtherTreeType>
857 template<
typename OtherTreeType>
870 template<
typename OtherTreeType>
907 #if OPENVDB_ABI_VERSION_NUMBER >= 8
954 void readBuffers(std::istream&,
const CoordBBox&)
override;
965 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
989 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1011 template<
typename Gr
idType>
1012 inline typename GridType::Ptr
1015 return GridBase::grid<GridType>(grid);
1027 template<
typename Gr
idType>
1028 inline typename GridType::ConstPtr
1031 return GridBase::constGrid<GridType>(grid);
1044 template<
typename Gr
idType>
1045 inline typename GridType::Ptr
1048 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
1049 return gridPtrCast<GridType>(grid->deepCopyGrid());
1053 template<
typename Gr
idType>
1054 inline typename GridType::Ptr
1057 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
1069 template<
typename _TreeType>
1099 template<
typename _TreeType>
1128 template<
typename _TreeType>
1169 template<
typename LeafNodeType>
1175 template<
typename RootNodeType>
1182 template<
typename TreeType>
1191 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1196 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
1200 template<
typename Gr
idType>
1201 inline typename GridType::Ptr
1206 if (grid && grid->type() == GridType::gridType()) {
1207 return StaticPtrCast<GridType>(
grid);
1209 return typename GridType::Ptr();
1213 template<
typename Gr
idType>
1214 inline typename GridType::ConstPtr
1217 return ConstPtrCast<const GridType>(
1218 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1222 template<
typename Gr
idType>
1223 inline typename GridType::ConstPtr
1226 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(
grid));
1230 template<
typename Gr
idType>
1231 inline typename GridType::ConstPtr
1234 return ConstPtrCast<const GridType>(
1235 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1249 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
1257 template<
typename TreeT>
1263 template<
typename TreeT>
1269 template<
typename TreeT>
1272 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1276 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1277 template<
typename TreeT>
1282 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1287 template<
typename TreeT>
1295 template<
typename TreeT>
1296 template<
typename OtherTreeType>
1299 mTree(new
TreeType(other.constTree()))
1304 template<
typename TreeT>
1312 template<
typename TreeT>
1321 template<
typename TreeT>
1330 template<
typename TreeT>
1334 return Ptr(
new Grid(background));
1339 template<
typename TreeT>
1348 template<
typename TreeT>
1359 template<
typename TreeT>
1367 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1368 template<
typename TreeT>
1373 this->constTransformPtr());
1374 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1378 template<
typename TreeT>
1382 return this->copyReplacingMetadataAndTransform(*
this, xform);
1385 template<
typename TreeT>
1390 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1396 template<
typename TreeT>
1404 template<
typename TreeT>
1414 template<
typename TreeT>
1418 return this->
copy();
1421 template<
typename TreeT>
1425 return this->
copy();
1428 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1429 template<
typename TreeT>
1433 return this->copyReplacingMetadata(meta);
1436 template<
typename TreeT>
1440 return this->copyReplacingTransform(xform);
1443 template<
typename TreeT>
1448 return this->copyReplacingMetadataAndTransform(meta, xform);
1452 template<
typename TreeT>
1456 return this->copyWithNewTree();
1463 template<
typename TreeT>
1467 return mTree.use_count() == 1;
1471 template<
typename TreeT>
1475 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1476 if (tree->type() != TreeType::treeType()) {
1478 + tree->type() +
" to a grid of type " + this->
type());
1480 mTree = StaticPtrCast<TreeType>(tree);
1484 template<
typename TreeT>
1488 mTree.reset(
new TreeType(this->background()));
1495 template<
typename TreeT>
1499 tree().sparseFill(bbox, value, active);
1503 template<
typename TreeT>
1507 this->sparseFill(bbox, value, active);
1510 template<
typename TreeT>
1514 tree().denseFill(bbox, value, active);
1517 template<
typename TreeT>
1522 this->tree().prune(static_cast<ValueType>(
value));
1525 template<
typename TreeT>
1532 template<
typename TreeT>
1536 tree().merge(other.tree(),
policy);
1540 template<
typename TreeT>
1541 template<
typename OtherTreeType>
1545 tree().topologyUnion(other.tree());
1549 template<
typename TreeT>
1550 template<
typename OtherTreeType>
1554 tree().topologyIntersection(other.tree());
1558 template<
typename TreeT>
1559 template<
typename OtherTreeType>
1563 tree().topologyDifference(other.tree());
1570 template<
typename TreeT>
1574 tree().evalMinMax(minVal, maxVal);
1578 template<
typename TreeT>
1583 tree().evalActiveVoxelBoundingBox(bbox);
1588 template<
typename TreeT>
1593 const bool nonempty = tree().evalActiveVoxelDim(dim);
1594 return (nonempty ? dim : Coord());
1604 template<
typename TreeT>
1608 tree().readTopology(is, saveFloatAsHalf());
1612 template<
typename TreeT>
1616 tree().writeTopology(os, saveFloatAsHalf());
1620 template<
typename TreeT>
1625 tree().readBuffers(is, saveFloatAsHalf());
1627 uint16_t numPasses = 1;
1628 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1631 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1632 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1633 meta->setPass(pass);
1634 tree().readBuffers(is, saveFloatAsHalf());
1642 template<
typename TreeT>
1647 tree().readBuffers(is, bbox, saveFloatAsHalf());
1649 uint16_t numPasses = 1;
1650 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1653 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1654 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1655 meta->setPass(pass);
1656 tree().readBuffers(is, saveFloatAsHalf());
1665 template<
typename TreeT>
1669 tree().readNonresidentBuffers();
1673 template<
typename TreeT>
1677 if (!hasMultiPassIO()) {
1678 tree().writeBuffers(os, saveFloatAsHalf());
1683 uint16_t numPasses = 1;
1684 meta->setCountingPasses(
true);
1686 tree().writeBuffers(os, saveFloatAsHalf());
1687 numPasses =
static_cast<uint16_t
>(meta->pass());
1688 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1689 meta->setCountingPasses(
false);
1692 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1693 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1694 meta->setPass(pass);
1695 tree().writeBuffers(os, saveFloatAsHalf());
1702 template<
typename TreeT>
1710 template<
typename TreeT>
1714 tree().print(os, verboseLevel);
1716 if (metaCount() > 0) {
1717 os <<
"Additional metadata:" << std::endl;
1719 os <<
" " << it->first;
1722 if (!value.empty()) os <<
": " << value;
1728 os <<
"Transform:" << std::endl;
1737 template<
typename Gr
idType>
1738 inline typename GridType::Ptr
1741 return GridType::create(background);
1745 template<
typename Gr
idType>
1746 inline typename GridType::Ptr
1749 return GridType::create();
1753 template<
typename TreePtrType>
1754 inline typename Grid<typename TreePtrType::element_type>::Ptr
1757 using TreeType =
typename TreePtrType::element_type;
1762 template<
typename Gr
idType>
1763 typename GridType::Ptr
1766 using ValueType =
typename GridType::ValueType;
1770 "level-set grids must be floating-point-valued");
1772 typename GridType::Ptr grid = GridType::create(
1773 static_cast<ValueType>(voxelSize * halfWidth));
1784 namespace internal {
1787 template<
typename OpT,
typename GridBaseT,
typename T,
typename ...Ts>
1788 struct GridApplyImpl {
static bool apply(GridBaseT&, OpT&) {
return false; } };
1792 template<
typename OpT,
typename GridBaseT,
typename GridT,
typename ...GridTs>
1793 struct GridApplyImpl<OpT, GridBaseT, TypeList<GridT, GridTs...>>
1795 static bool apply(GridBaseT& grid, OpT& op)
1797 if (grid.template isType<GridT>()) {
1801 return GridApplyImpl<OpT, GridBaseT, TypeList<GridTs...>>::apply(grid, op);
1809 template<
typename Gr
idTypeListT,
typename OpT>
1813 return internal::GridApplyImpl<OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1816 template<
typename Gr
idTypeListT,
typename OpT>
1820 return internal::GridApplyImpl<OpT, GridBase, GridTypeListT>::apply(*
this, op);
1823 template<
typename Gr
idTypeListT,
typename OpT>
1827 return internal::GridApplyImpl<const OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1830 template<
typename Gr
idTypeListT,
typename OpT>
1834 return internal::GridApplyImpl<const OpT, GridBase, GridTypeListT>::apply(*
this, op);
1840 #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...
bool isTreeUnique() const final
Return true if tree is not shared with another grid.
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)
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
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...
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
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
GLuint const GLchar * name
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
GLuint GLenum GLenum transform
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...
GLint GLint GLsizei GLint GLenum GLenum type
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.
void print(std::FILE *f, const S &format_str, Args &&...args)
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
GLboolean GLboolean GLboolean GLboolean a
bool apply(OpT &) const
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid...
typename GridType::Ptr GridPtrType
GLsizei const GLchar *const * string
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
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
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
GLsizei const GLfloat * value
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.
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.
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.
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.