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>
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 (*)();
129 static bool isRegistered(
const Name &
type);
132 static void clearRegistry();
142 virtual Name valueType()
const = 0;
145 template<
typename Gr
idType>
146 bool isType()
const {
return (this->
type() == GridType::gridType()); }
153 template<
typename Gr
idType>
155 template<
typename Gr
idType>
157 template<
typename Gr
idType>
158 static typename GridType::ConstPtr constGrid(
const GridBase::Ptr&);
159 template<
typename Gr
idType>
177 virtual bool isTreeUnique()
const = 0;
204 virtual void newTree() = 0;
209 virtual bool empty()
const = 0;
211 virtual void clear() = 0;
222 virtual void pruneGrid(
float tolerance = 0.0) = 0;
228 void clipGrid(
const BBoxd&);
262 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&)
const;
263 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&);
264 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&)
const;
265 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&);
283 bool saveFloatAsHalf()
const;
284 void setSaveFloatAsHalf(
bool);
295 void clearGridClass();
321 void clearVectorType();
341 bool isInWorldSpace()
const;
343 void setIsInWorldSpace(
bool);
369 virtual Index64 activeVoxelCount()
const = 0;
373 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
376 virtual Coord evalActiveVoxelDim()
const = 0;
379 virtual Index64 memUsage()
const = 0;
385 void addStatsMetadata();
451 virtual void readTopology(std::istream&) = 0;
454 virtual void writeTopology(std::ostream&)
const = 0;
457 virtual void readBuffers(std::istream&) = 0;
459 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
465 virtual void readNonresidentBuffers()
const = 0;
467 virtual void writeBuffers(std::ostream&)
const = 0;
475 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
482 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
495 static void registerGrid(
const Name&
type, GridFactory);
497 static void unregisterGrid(
const Name&
type);
538 template<
typename Gr
idPtrContainerT>
543 typename GridPtrContainerT::const_iterator it =
544 std::find_if(container.begin(), container.end(),
GridNamePred(name));
545 return (it == container.end() ? GridPtrT() : *it);
549 template<
typename KeyT,
typename Gr
idPtrT>
553 using GridPtrMapT = std::map<KeyT, GridPtrT>;
554 for (
typename GridPtrMapT::const_iterator it = container.begin(),
end = container.end();
557 const GridPtrT& grid = it->second;
558 if (grid && grid->getName() == name)
return grid;
569 template<
typename _TreeType>
570 class Grid:
public GridBase
600 template<
typename OtherValueType>
632 template<
typename OtherTreeType>
806 void pruneGrid(
float tolerance = 0.0)
override;
834 template<
typename OtherTreeType>
849 template<
typename OtherTreeType>
862 template<
typename OtherTreeType>
878 tools::minMax(grid->tree()). Use threaded = false for serial execution")
956 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
1000 template<
typename Gr
idType>
1001 inline typename GridType::Ptr
1004 return GridBase::grid<GridType>(grid);
1016 template<
typename Gr
idType>
1017 inline typename GridType::ConstPtr
1020 return GridBase::constGrid<GridType>(grid);
1033 template<
typename Gr
idType>
1034 inline typename GridType::Ptr
1037 if (!grid || !grid->isType<
GridType>())
return typename GridType::Ptr();
1038 return gridPtrCast<GridType>(grid->deepCopyGrid());
1042 template<
typename Gr
idType>
1043 inline typename GridType::Ptr
1058 template<
typename _TreeType>
1088 template<
typename _TreeType>
1117 template<
typename _TreeType>
1158 template<
typename LeafNodeType>
1164 template<
typename RootNodeType>
1171 template<
typename TreeType>
1184 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
1187 template<
typename Gr
idType>
1188 inline typename GridType::Ptr
1193 if (grid && grid->type() == GridType::gridType()) {
1194 return StaticPtrCast<GridType>(
grid);
1196 return typename GridType::Ptr();
1200 template<
typename Gr
idType>
1201 inline typename GridType::ConstPtr
1204 return ConstPtrCast<const GridType>(
1205 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1209 template<
typename Gr
idType>
1210 inline typename GridType::ConstPtr
1213 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(
grid));
1217 template<
typename Gr
idType>
1218 inline typename GridType::ConstPtr
1221 return ConstPtrCast<const GridType>(
1222 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1236 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
1244 template<
typename TreeT>
1250 template<
typename TreeT>
1256 template<
typename TreeT>
1259 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1263 template<
typename TreeT>
1268 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1272 template<
typename TreeT>
1280 template<
typename TreeT>
1281 template<
typename OtherTreeType>
1284 mTree(new
TreeType(other.constTree()))
1289 template<
typename TreeT>
1297 template<
typename TreeT>
1306 template<
typename TreeT>
1315 template<
typename TreeT>
1319 return Ptr(
new Grid(background));
1324 template<
typename TreeT>
1333 template<
typename TreeT>
1344 template<
typename TreeT>
1352 template<
typename TreeT>
1357 this->constTransformPtr());
1358 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1362 template<
typename TreeT>
1366 return this->copyReplacingMetadataAndTransform(*
this, xform);
1369 template<
typename TreeT>
1374 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1379 template<
typename TreeT>
1387 template<
typename TreeT>
1397 template<
typename TreeT>
1401 return this->
copy();
1404 template<
typename TreeT>
1408 return this->
copy();
1411 template<
typename TreeT>
1415 return this->copyReplacingMetadata(meta);
1418 template<
typename TreeT>
1422 return this->copyReplacingTransform(xform);
1425 template<
typename TreeT>
1430 return this->copyReplacingMetadataAndTransform(meta, xform);
1433 template<
typename TreeT>
1437 return this->copyWithNewTree();
1444 template<
typename TreeT>
1448 return mTree.use_count() == 1;
1452 template<
typename TreeT>
1456 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1457 if (tree->type() != TreeType::treeType()) {
1459 + tree->type() +
" to a grid of type " + this->
type());
1461 mTree = StaticPtrCast<TreeType>(tree);
1465 template<
typename TreeT>
1469 mTree.reset(
new TreeType(this->background()));
1476 template<
typename TreeT>
1480 tree().sparseFill(bbox, value, active);
1484 template<
typename TreeT>
1488 this->sparseFill(bbox, value, active);
1491 template<
typename TreeT>
1495 tree().denseFill(bbox, value, active);
1498 template<
typename TreeT>
1503 this->tree().prune(static_cast<ValueType>(
value));
1506 template<
typename TreeT>
1513 template<
typename TreeT>
1517 tree().merge(other.tree(),
policy);
1521 template<
typename TreeT>
1522 template<
typename OtherTreeType>
1526 tree().topologyUnion(other.tree());
1530 template<
typename TreeT>
1531 template<
typename OtherTreeType>
1535 tree().topologyIntersection(other.tree());
1539 template<
typename TreeT>
1540 template<
typename OtherTreeType>
1544 tree().topologyDifference(other.tree());
1551 template<
typename TreeT>
1556 tree().evalMinMax(minVal, maxVal);
1561 template<
typename TreeT>
1566 tree().evalActiveVoxelBoundingBox(bbox);
1571 template<
typename TreeT>
1576 const bool nonempty = tree().evalActiveVoxelDim(dim);
1577 return (nonempty ? dim : Coord());
1587 template<
typename TreeT>
1591 tree().readTopology(is, saveFloatAsHalf());
1595 template<
typename TreeT>
1599 tree().writeTopology(os, saveFloatAsHalf());
1603 template<
typename TreeT>
1608 tree().readBuffers(is, saveFloatAsHalf());
1610 uint16_t numPasses = 1;
1611 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1614 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1615 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1616 meta->setPass(pass);
1617 tree().readBuffers(is, saveFloatAsHalf());
1625 template<
typename TreeT>
1630 tree().readBuffers(is, bbox, saveFloatAsHalf());
1632 uint16_t numPasses = 1;
1633 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1636 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1637 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1638 meta->setPass(pass);
1639 tree().readBuffers(is, saveFloatAsHalf());
1648 template<
typename TreeT>
1652 tree().readNonresidentBuffers();
1656 template<
typename TreeT>
1660 if (!hasMultiPassIO()) {
1661 tree().writeBuffers(os, saveFloatAsHalf());
1666 uint16_t numPasses = 1;
1667 meta->setCountingPasses(
true);
1669 tree().writeBuffers(os, saveFloatAsHalf());
1670 numPasses =
static_cast<uint16_t
>(meta->pass());
1671 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1672 meta->setCountingPasses(
false);
1675 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1676 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1677 meta->setPass(pass);
1678 tree().writeBuffers(os, saveFloatAsHalf());
1685 template<
typename TreeT>
1693 template<
typename TreeT>
1697 tree().print(os, verboseLevel);
1699 if (metaCount() > 0) {
1700 os <<
"Additional metadata:" << std::endl;
1702 os <<
" " << it->first;
1705 if (!value.empty()) os <<
": " << value;
1711 os <<
"Transform:" << std::endl;
1720 template<
typename Gr
idType>
1721 inline typename GridType::Ptr
1724 return GridType::create(background);
1728 template<
typename Gr
idType>
1729 inline typename GridType::Ptr
1732 return GridType::create();
1736 template<
typename TreePtrType>
1737 inline typename Grid<typename TreePtrType::element_type>::Ptr
1740 using TreeType =
typename TreePtrType::element_type;
1745 template<
typename Gr
idType>
1746 typename GridType::Ptr
1753 "level-set grids must be floating-point-valued");
1755 typename GridType::Ptr grid = GridType::create(
1756 static_cast<ValueType>(voxelSize * halfWidth));
1766 template<
typename Gr
idTypeListT,
typename OpT>
1770 return GridTypeListT::template apply<OpT&, const GridBase>(
std::ref(op), *
this);
1773 template<
typename Gr
idTypeListT,
typename OpT>
1777 return GridTypeListT::template apply<OpT&, GridBase>(
std::ref(op), *
this);
1780 template<
typename Gr
idTypeListT,
typename OpT>
1784 return GridTypeListT::template apply<const OpT&, const GridBase>(
std::ref(op), *
this);
1787 template<
typename Gr
idTypeListT,
typename OpT>
1791 return GridTypeListT::template apply<const OpT&, GridBase>(
std::ref(op), *
this);
1798 #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.
GridType
List of types that are currently supported by NanoVDB.
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
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
static const TreeType & constTree(TreeType &t)
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
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
GLboolean GLboolean GLboolean GLboolean a
#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
The Value Accessor Implementation and API methods. The majoirty of the API matches the API of a compa...
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
typename NonConstGridType::Ptr NonConstGridPtrType
**But if you need a result
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 ...
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
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 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.
GLuint const GLchar * name
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
ValueType &maxVal const
Return the number of active voxels.
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
GA_API const UT_StringHolder transform
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.
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
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...
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
ValueAccessorImpl< TreeType, IsSafe, MutexType, openvdb::make_index_sequence< CacheLevels >> ValueAccessor
Default alias for a ValueAccessor. This is simply a helper alias for the generic definition but takes...
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.
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.
typename TreeType::Ptr TreePtrType
std::set< GridBase::ConstPtr > GridCPtrSet
bool evalMinMax(const PointDataTreeT &points, const std::string &attribute, ValueT &min, ValueT &max, const FilterT &filter, typename PointDataTreeT::template ValueConverter< ValueT >::Type *minTree, typename PointDataTreeT::template ValueConverter< ValueT >::Type *maxTree)
Evaluates the minimum and maximum values of a point attribute and returns whether the values are vali...
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)
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
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.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
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
OPENVDB_DEPRECATED_MESSAGE("Switch from grid->evalMinMax(minVal, maxVal) to \
tools::minMax(grid->tree()). Use threaded = false for serial execution") void evalMinMax(ValueType &minVal
Return the minimum and maximum active values in this grid.
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.