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&);
274 void setName(
const std::string&);
277 std::string getCreator()
const;
279 void setCreator(
const std::string&);
283 bool saveFloatAsHalf()
const;
284 void setSaveFloatAsHalf(
bool);
295 void clearGridClass();
300 static std::string gridClassToString(
GridClass);
302 static std::string gridClassToMenuName(
GridClass);
307 static GridClass stringToGridClass(
const std::string&);
321 void clearVectorType();
326 static std::string vecTypeToString(
VecType);
329 static std::string vecTypeExamples(
VecType);
332 static std::string vecTypeDescription(
VecType);
333 static VecType stringToVecType(
const std::string&);
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>
1146 template<
typename _TreeType>
1193 template<
typename LeafNodeType>
1199 template<
typename RootNodeType>
1206 template<
typename TreeType>
1219 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
1222 template<
typename Gr
idType>
1223 inline typename GridType::Ptr
1228 if (grid && grid->type() == GridType::gridType()) {
1229 return StaticPtrCast<GridType>(
grid);
1231 return typename GridType::Ptr();
1235 template<
typename Gr
idType>
1236 inline typename GridType::ConstPtr
1239 return ConstPtrCast<const GridType>(
1240 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1244 template<
typename Gr
idType>
1245 inline typename GridType::ConstPtr
1248 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(
grid));
1252 template<
typename Gr
idType>
1253 inline typename GridType::ConstPtr
1256 return ConstPtrCast<const GridType>(
1257 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1271 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
1279 template<
typename TreeT>
1285 template<
typename TreeT>
1291 template<
typename TreeT>
1294 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1298 template<
typename TreeT>
1303 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1307 template<
typename TreeT>
1315 template<
typename TreeT>
1316 template<
typename OtherTreeType>
1319 mTree(new
TreeType(other.constTree()))
1324 template<
typename TreeT>
1332 template<
typename TreeT>
1341 template<
typename TreeT>
1350 template<
typename TreeT>
1354 return Ptr(
new Grid(background));
1359 template<
typename TreeT>
1368 template<
typename TreeT>
1379 template<
typename TreeT>
1387 template<
typename TreeT>
1392 this->constTransformPtr());
1393 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1397 template<
typename TreeT>
1401 return this->copyReplacingMetadataAndTransform(*
this, xform);
1404 template<
typename TreeT>
1409 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1414 template<
typename TreeT>
1422 template<
typename TreeT>
1432 template<
typename TreeT>
1436 return this->
copy();
1439 template<
typename TreeT>
1443 return this->
copy();
1446 template<
typename TreeT>
1450 return this->copyReplacingMetadata(meta);
1453 template<
typename TreeT>
1457 return this->copyReplacingTransform(xform);
1460 template<
typename TreeT>
1465 return this->copyReplacingMetadataAndTransform(meta, xform);
1468 template<
typename TreeT>
1472 return this->copyWithNewTree();
1479 template<
typename TreeT>
1483 return mTree.use_count() == 1;
1487 template<
typename TreeT>
1491 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1492 if (tree->type() != TreeType::treeType()) {
1494 + tree->type() +
" to a grid of type " + this->
type());
1496 mTree = StaticPtrCast<TreeType>(tree);
1500 template<
typename TreeT>
1504 mTree.reset(
new TreeType(this->background()));
1511 template<
typename TreeT>
1515 tree().sparseFill(bbox, value, active);
1519 template<
typename TreeT>
1523 this->sparseFill(bbox, value, active);
1526 template<
typename TreeT>
1530 tree().denseFill(bbox, value, active);
1533 template<
typename TreeT>
1538 this->tree().prune(static_cast<ValueType>(
value));
1541 template<
typename TreeT>
1548 template<
typename TreeT>
1552 tree().merge(other.tree(),
policy);
1556 template<
typename TreeT>
1557 template<
typename OtherTreeType>
1561 tree().topologyUnion(other.tree());
1565 template<
typename TreeT>
1566 template<
typename OtherTreeType>
1570 tree().topologyIntersection(other.tree());
1574 template<
typename TreeT>
1575 template<
typename OtherTreeType>
1579 tree().topologyDifference(other.tree());
1586 template<
typename TreeT>
1591 tree().evalMinMax(minVal, maxVal);
1596 template<
typename TreeT>
1601 tree().evalActiveVoxelBoundingBox(bbox);
1606 template<
typename TreeT>
1611 const bool nonempty = tree().evalActiveVoxelDim(dim);
1612 return (nonempty ? dim : Coord());
1622 template<
typename TreeT>
1626 tree().readTopology(is, saveFloatAsHalf());
1630 template<
typename TreeT>
1634 tree().writeTopology(os, saveFloatAsHalf());
1638 template<
typename TreeT>
1643 tree().readBuffers(is, saveFloatAsHalf());
1645 uint16_t numPasses = 1;
1646 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1649 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1650 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1651 meta->setPass(pass);
1652 tree().readBuffers(is, saveFloatAsHalf());
1660 template<
typename TreeT>
1665 tree().readBuffers(is, bbox, saveFloatAsHalf());
1667 uint16_t numPasses = 1;
1668 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1671 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1672 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1673 meta->setPass(pass);
1674 tree().readBuffers(is, saveFloatAsHalf());
1683 template<
typename TreeT>
1687 tree().readNonresidentBuffers();
1691 template<
typename TreeT>
1695 if (!hasMultiPassIO()) {
1696 tree().writeBuffers(os, saveFloatAsHalf());
1701 uint16_t numPasses = 1;
1702 meta->setCountingPasses(
true);
1704 tree().writeBuffers(os, saveFloatAsHalf());
1705 numPasses =
static_cast<uint16_t
>(meta->pass());
1706 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1707 meta->setCountingPasses(
false);
1710 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1711 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1712 meta->setPass(pass);
1713 tree().writeBuffers(os, saveFloatAsHalf());
1720 template<
typename TreeT>
1728 template<
typename TreeT>
1732 tree().print(os, verboseLevel);
1734 if (metaCount() > 0) {
1735 os <<
"Additional metadata:" << std::endl;
1737 os <<
" " << it->first;
1739 const std::string
value = it->second->str();
1740 if (!value.empty()) os <<
": " << value;
1746 os <<
"Transform:" << std::endl;
1755 template<
typename Gr
idType>
1756 inline typename GridType::Ptr
1759 return GridType::create(background);
1763 template<
typename Gr
idType>
1764 inline typename GridType::Ptr
1767 return GridType::create();
1771 template<
typename TreePtrType>
1772 inline typename Grid<typename TreePtrType::element_type>::Ptr
1775 using TreeType =
typename TreePtrType::element_type;
1780 template<
typename Gr
idType>
1781 typename GridType::Ptr
1788 "level-set grids must be floating-point-valued");
1790 typename GridType::Ptr grid = GridType::create(
1791 static_cast<ValueType>(voxelSize * halfWidth));
1801 template<
typename Gr
idTypeListT,
typename OpT>
1805 return GridTypeListT::template apply<OpT&, const GridBase>(
std::ref(op), *
this);
1808 template<
typename Gr
idTypeListT,
typename OpT>
1812 return GridTypeListT::template apply<OpT&, GridBase>(
std::ref(op), *
this);
1815 template<
typename Gr
idTypeListT,
typename OpT>
1819 return GridTypeListT::template apply<const OpT&, const GridBase>(
std::ref(op), *
this);
1822 template<
typename Gr
idTypeListT,
typename OpT>
1826 return GridTypeListT::template apply<const OpT&, GridBase>(
std::ref(op), *
this);
1833 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
static const NonConstTreeType & constTree(const NonConstGridType &g)
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::Accessor Accessor
bool isTreeUnique() const final
Return true if tree is not shared with another grid.
typename _TreeType::ValueType ValueType
typename TreeType::ConstPtr ConstTreePtrType
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
static const NonConstTreeType & constTree(const NonConstGridType &g)
typename tree::ValueAccessor< TreeType > AccessorType
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
typename NonConstTreeType::Ptr NonConstTreePtrType
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
typename tree::ValueAccessor< const NonConstTreeType > ConstAccessorType
typename tree::ValueAccessor< TreeType > AccessorType
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.
typename _TreeType::UnsafeAccessor UnsafeAccessor
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
static NonConstTreeType & tree(NonConstTreeType &t)
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
SharedPtr< const Grid > ConstPtr
static const NonConstTreeType & constTree(const NonConstAccessorType &a)
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 NonConstTreeType & tree(const NonConstGridType &g)
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 NonConstTreeType & tree(const NonConstGridType &g)
GLsizei const GLfloat * value
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
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
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.
typename TreeType::Ptr TreePtrType
GridCPtrSet::const_iterator GridCPtrSetCIter
bool operator()(const GridBase::ConstPtr &g) const
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
static const NonConstTreeType & constTree(NonConstGridType &g)
typename NonConstGridType::Ptr NonConstGridPtrType
**But if you need a result
static const char *const META_GRID_CLASS
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
static const NonConstTreeType & tree(const NonConstTreeType &t)
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
static NonConstTreeType & tree(NonConstGridType &g)
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...
static const NonConstTreeType & tree(const NonConstGridType &g)
static const NonConstTreeType & constTree(const NonConstGridType &g)
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
GridCPtrSet::iterator GridCPtrSetIter
static const char *const META_FILE_VOXEL_COUNT
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
#define OPENVDB_ASSERT(X)
std::shared_ptr< T > SharedPtr
static const NonConstTreeType & tree(const ConstAccessorType &a)
Abstract base class for typed grids.
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
static const char *const META_FILE_BBOX_MIN
static const NonConstTreeType & tree(ConstAccessorType &a)
typename std::remove_const< TreeType >::type NonConstTreeType
GLint GLint GLsizei GLint GLenum GLenum type
static const NonConstTreeType & tree(const NonConstAccessorType &a)
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 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.
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
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...
static const NonConstTreeType & constTree(const ConstAccessorType &a)
typename GridType::ConstPtr ConstGridPtrType
static const NonConstTreeType & tree(const NonConstTreeType &t)
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
static const NonConstTreeType & constTree(const NonConstTreeType &t)
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
typename _TreeType::ValueOffIter ValueOffIter
static NonConstTreeType & tree(NonConstTreeType &t)
typename NonConstGridType::Ptr NonConstGridPtrType
typename GridType::ConstPtr ConstGridPtrType
Name type() const override
Return the name of this grid's type.
Index64 memUsage() const override
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 NonConstTreeType::Ptr NonConstTreePtrType
typename TreeType::ConstPtr ConstTreePtrType
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
GridNamePred(const Name &_name)
static const NonConstTreeType & constTree(const NonConstGridType &g)
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.
static const NonConstTreeType & tree(const NonConstTreeType &t)
static const NonConstTreeType & constTree(NonConstAccessorType &a)
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...
typename _TreeType::ConstUnsafeAccessor ConstUnsafeAccessor
const ValueType & background() const
Return this grid's background value.
Base class for typed trees.
static const NonConstTreeType & constTree(const NonConstTreeType &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 NonConstTreeType & tree(NonConstTreeType &t)
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
typename GridType::Ptr GridPtrType
Predicate functor that returns true for grids that have a specified name.
static NonConstTreeType & tree(NonConstGridType &g)
GridCPtrVec::iterator GridCPtrVecIter
static NonConstTreeType & tree(NonConstGridType &g)
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
static const NonConstTreeType & constTree(NonConstGridType &g)
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.
typename GridType::Ptr GridPtrType
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
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 _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
static NonConstTreeType & tree(NonConstTreeType &t)
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 NonConstTreeType & constTree(const NonConstTreeType &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.
static const NonConstTreeType & constTree(NonConstGridType &g)
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...
static const NonConstTreeType & constTree(NonConstTreeType &t)
SharedPtr< const TreeBase > ConstPtr
static const char *const META_GRID_CREATOR
typename std::remove_const< TreeType >::type NonConstTreeType
static const NonConstTreeType & constTree(NonConstTreeType &t)
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.
static const NonConstTreeType & tree(const NonConstGridType &g)
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 bool isRegistered()
Return true if this grid type is registered.
bool empty() const override
Return true if this grid contains only inactive background voxels.
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.
static const NonConstTreeType & constTree(NonConstTreeType &t)
typename TreeType::ValueType ValueType
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...
typename NonConstGridType::Ptr NonConstGridPtrType
typename _TreeType::ConstAccessor ConstAccessor
Grid()
Construct a new grid with background value zero.
static const NonConstTreeType & constTree(NonConstTreeType &t)
void readBuffers(std::istream &) override
Read all data buffers for this grid.
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
static const NonConstTreeType & constTree(ConstAccessorType &a)
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.
std::vector< GridBase::ConstPtr > GridCPtrVec
typename _TreeType::ValueAllIter ValueAllIter
static NonConstTreeType & tree(NonConstAccessorType &a)
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
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.
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
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 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)
static const NonConstTreeType & constTree(NonConstGridType &g)
typename GridType::ConstPtr ConstGridPtrType
static const NonConstTreeType & tree(const NonConstTreeType &t)
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.
static NonConstTreeType & tree(NonConstGridType &g)
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.