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>
83 using GridFactory =
Ptr (*)();
102 #if OPENVDB_ABI_VERSION_NUMBER >= 7 131 static bool isRegistered(
const Name &type);
134 static void clearRegistry();
142 virtual Name type()
const = 0;
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&);
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&);
276 std::string getName()
const;
278 void setName(
const std::string&);
281 std::string getCreator()
const;
283 void setCreator(
const std::string&);
287 bool saveFloatAsHalf()
const;
288 void setSaveFloatAsHalf(
bool);
299 void clearGridClass();
304 static std::string gridClassToString(
GridClass);
306 static std::string gridClassToMenuName(
GridClass);
311 static GridClass stringToGridClass(
const std::string&);
325 void clearVectorType();
330 static std::string vecTypeToString(
VecType);
333 static std::string vecTypeExamples(
VecType);
336 static std::string vecTypeDescription(
VecType);
337 static VecType stringToVecType(
const std::string&);
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();
434 Vec3d
voxelSize()
const {
return transform().voxelSize(); }
437 Vec3d
voxelSize(
const Vec3d& xyz)
const {
return transform().voxelSize(xyz); }
441 Vec3d
indexToWorld(
const Vec3d& xyz)
const {
return transform().indexToWorld(xyz); }
443 Vec3d
indexToWorld(
const Coord& ijk)
const {
return transform().indexToWorld(ijk); }
445 Vec3d
worldToIndex(
const Vec3d& xyz)
const {
return transform().worldToIndex(xyz); }
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>
545 inline typename GridPtrContainerT::value_type
548 using GridPtrT =
typename GridPtrContainerT::value_type;
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>
606 template<
typename OtherValueType>
638 template<
typename OtherTreeType>
649 Grid& operator=(
const Grid&) =
delete;
662 Ptr copyWithNewTree()
const;
678 #if OPENVDB_ABI_VERSION_NUMBER >= 7 717 Name type()
const override {
return this->gridType(); }
733 bool empty()
const override {
return tree().empty(); }
735 void clear()
override { tree().clear(); }
814 void pruneGrid(
float tolerance = 0.0)
override;
842 template<
typename OtherTreeType>
857 template<
typename OtherTreeType>
870 template<
typename OtherTreeType>
881 CoordBBox evalActiveVoxelBoundingBox()
const override;
883 Coord evalActiveVoxelDim()
const override;
907 #if OPENVDB_ABI_VERSION_NUMBER >= 8 908 bool isTreeUnique()
const final;
910 bool isTreeUnique()
const;
936 void newTree()
override;
946 void readTopology(std::istream&)
override;
949 void writeTopology(std::ostream&)
const override;
952 void readBuffers(std::istream&)
override;
954 void readBuffers(std::istream&,
const CoordBBox&)
override;
960 void readNonresidentBuffers()
const override;
962 void writeBuffers(std::ostream&)
const override;
965 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
972 static inline bool hasMultiPassIO();
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
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 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)));
1257 template<
typename TreeT>
1263 template<
typename TreeT>
1269 template<
typename TreeT>
1276 #if OPENVDB_ABI_VERSION_NUMBER >= 7 1277 template<
typename TreeT>
1287 template<
typename TreeT>
1295 template<
typename TreeT>
1296 template<
typename OtherTreeType>
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>
1378 template<
typename TreeT>
1385 template<
typename TreeT>
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>
1436 template<
typename TreeT>
1443 template<
typename TreeT>
1452 template<
typename TreeT>
1463 template<
typename TreeT>
1467 return mTree.use_count() == 1;
1471 template<
typename TreeT>
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>
1495 template<
typename TreeT>
1499 tree().sparseFill(bbox, value, active);
1503 template<
typename TreeT>
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>
1612 template<
typename TreeT>
1620 template<
typename TreeT>
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);
1642 template<
typename TreeT>
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);
1665 template<
typename TreeT>
1669 tree().readNonresidentBuffers();
1673 template<
typename TreeT>
1683 uint16_t numPasses = 1;
1684 meta->setCountingPasses(
true);
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);
1702 template<
typename TreeT>
1710 template<
typename TreeT>
1714 tree().print(os, verboseLevel);
1717 os <<
"Additional metadata:" << std::endl;
1719 os <<
" " << it->first;
1721 const std::string
value = it->second->str();
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>
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 _TreeType TreeType
Definition: Grid.h:1102
Index64 memUsage() const override
Definition: Grid.h:889
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:879
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1675
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1527
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:197
static const char *const META_GRID_NAME
Definition: Grid.h:357
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:536
void topologyUnion(const Grid< OtherTreeType > &other)
Union this grid's set of active values with the active values of the other grid, whose value type may...
Definition: Grid.h:1543
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:979
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1093
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1133
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1143
static TreeType & tree(TreeType &t)
Definition: Grid.h:1117
Name name
Definition: Grid.h:540
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...
Definition: Grid.h:1445
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:709
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:359
SharedPtr< Grid > Ptr
Definition: Grid.h:579
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels...
Definition: Grid.h:748
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...
Definition: Grid.h:1370
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
typename GridType::Ptr GridPtrType
Definition: Grid.h:1138
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:589
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1122
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
Definition: Grid.h:445
Base class for typed trees.
Definition: Tree.h:36
GridNamePred(const Name &_name)
Definition: Grid.h:538
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1113
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1151
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1105
Abstract base class for typed grids.
Definition: Grid.h:77
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:522
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:363
SharedPtr< T > StaticPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that points to the same object as the given pointer after a static_cast...
Definition: Types.h:146
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:529
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1154
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1258
static TreeType & tree(TreeType &t)
Definition: Grid.h:1087
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1120
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:919
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:441
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1073
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1580
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1519
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1590
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:495
Mat3< Type1 > cwiseAdd(const Mat3< Type1 > &m, const Type2 s)
Definition: Mat3.h:820
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1084
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1755
void writeTopology(std::ostream &) const override
Write the grid topology to a stream. This will write only the grid structure, not the actual data buf...
Definition: Grid.h:1614
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:516
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1150
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1152
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1121
TreePtrType treePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:900
Ptr copy()
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition: Grid.h:1398
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:439
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:408
GridBase(GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:498
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:591
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1323
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1080
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1103
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition: Grid.h:1505
~Grid() override
Definition: Grid.h:646
Definition: Exceptions.h:65
static const char *const META_FILE_DELAYED_LOAD
Definition: Grid.h:366
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:717
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1134
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:520
MergePolicy
Definition: Types.h:467
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:597
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:588
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
Definition: version.h.in:249
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:361
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1135
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1119
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:407
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:763
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...
Definition: Grid.h:1416
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:476
static TreeType & tree(GridType &g)
Definition: Grid.h:1118
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:722
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1104
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1074
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:517
void sparseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition: Grid.h:1497
BBox< Coord > CoordBBox
Definition: NanoVDB.h:1658
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:514
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 ...
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
static const char *const META_GRID_CREATOR
Definition: Grid.h:356
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1090
static const char *const META_GRID_CLASS
Definition: Grid.h:355
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:524
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1155
SharedPtr< TreeBase > Ptr
Definition: Tree.h:39
TreeBase::ConstPtr constBaseTreePtr() const override
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:903
double Real
Definition: Types.h:60
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1089
static GridType::Ptr grid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
Definition: Grid.h:1202
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:641
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:527
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:437
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:765
openvdb::GridBase Grid
Definition: Utils.h:34
~GridBase() override
Definition: Grid.h:86
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1170
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1094
_TreeType TreeType
Definition: Grid.h:582
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:777
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:917
std::pair< ValueT, ValueT > evalMinMax(const PointDataTreeT &points, const std::string &attribute, const FilterT &filter=NullFilter())
Evaluates the minimum and maximum values of a point attribute.
Definition: PointStatistics.h:697
math::Transform::Ptr transformPtr()
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:406
TreeBase::Ptr baseTreePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:1240
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:519
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1140
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:40
std::string Name
Definition: Name.h:17
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:417
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:539
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:730
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1081
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:474
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:711
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:584
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:733
ConstTreePtrType constTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:902
static TreeType & tree(GridType &g)
Definition: Grid.h:1147
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...
Definition: Grid.h:1431
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:521
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.
Definition: Grid.h:1552
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:767
uint64_t Index64
Definition: Types.h:53
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:752
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1473
Definition: Exceptions.h:13
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:364
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:362
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:358
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:735
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...
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:532
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:525
ConstTreePtrType treePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:901
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:592
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:580
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:486
ValueT value
Definition: GridBuilder.h:1287
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1486
bool apply(OpT &) const
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid...
Definition: Grid.h:1811
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:434
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:595
GridType::ConstPtr gridConstPtrCast(const GridBase::ConstPtr &grid)
Cast a generic const grid pointer to a const pointer to a grid of a concrete class.
Definition: Grid.h:1029
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:740
bool isTreeUnique() const final
Return true if tree is not shared with another grid.
Definition: Grid.h:1465
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1144
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:750
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:773
typename TreeType::ValueType ValueType
Definition: Grid.h:1082
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.
Definition: Grid.h:1561
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:775
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1572
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:28
typename _TreeType::ValueType ValueType
Definition: Grid.h:585
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:607
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1085
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1148
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 char *const META_VECTOR_TYPE
Definition: Grid.h:360
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1132
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1123
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:216
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 ...
Definition: Grid.h:1454
GridType::Ptr createLevelSet(Real voxelSize=1.0, Real halfWidth=LEVEL_SET_HALF_WIDTH)
Create a new grid of type GridType classified as a "Level Set", i.e., a narrow-band level set...
Definition: Grid.h:1764
VecType
Definition: Types.h:444
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:526
void readTopology(std::istream &) override
Read the grid topology from a stream. This will read only the grid structure, not the actual data buf...
Definition: Grid.h:1606
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value and ensure that those voxels are a...
Definition: Grid.h:1512
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1106
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:779
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:719
static TreeType & tree(GridType &g)
Definition: Grid.h:1088
_TreeType TreeType
Definition: Grid.h:1072
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1124
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:596
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1110
Definition: Exceptions.h:64
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:530
typename TreeType::ValueType ValueType
Definition: Grid.h:1141
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1076
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
Definition: Grid.h:1704
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1142
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1534
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:148
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1075
tree::TreeBase TreeBase
Definition: Grid.h:26
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1149
GridType::Ptr gridPtrCast(const GridBase::Ptr &grid)
Cast a generic grid pointer to a pointer to a grid of a concrete class.
Definition: Grid.h:1013
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:769
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:531
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:515
typename TreeType::ValueType ValueType
Definition: Grid.h:1112
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1153
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1083
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:443
TreeBase::ConstPtr baseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:173
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:192
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.
Definition: Grid.h:1438
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:598
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:187
typename _TreeType::BuildType BuildType
Definition: Grid.h:586
typename std::remove_const< ToType >::type Type
Definition: Types.h:400
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1247
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1139
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...
Definition: Grid.h:1387
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:981
GridPtrT findGridByName(const std::map< KeyT, GridPtrT > &container, const Name &name)
Return the first grid in the given map whose name is name.
Definition: Grid.h:557
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
Definition: Grid.h:1224
Definition: ValueAccessor.h:182
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:416
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1111
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:771
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1115
typename GridType::Ptr GridPtrType
Definition: Grid.h:1109
typename GridType::Ptr GridPtrType
Definition: Grid.h:1079
static TreeType & tree(TreeType &t)
Definition: Grid.h:1146
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1622
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:365
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1712
void print(const ast::Node &node, const bool numberStatements=true, std::ostream &os=std::cout, const char *indent=" ")
Writes a descriptive printout of a Node hierarchy into a target stream.
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1114
GridClass
Definition: Types.h:414
_TreeType TreeType
Definition: Grid.h:1131
GridType::Ptr deepCopyTypedGrid(const GridBase &grid)
Return a pointer to a deep copy of the given grid, provided that the grid's concrete type is GridType...
Definition: Grid.h:1055
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1070
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:415
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:422
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:583
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1092
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:983
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:593
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:918
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1091
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.
Definition: Grid.h:1380
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:760
Ptr copyWithNewTree() const
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition: Grid.h:1406
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202
void readNonresidentBuffers() const override
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
Definition: Grid.h:1667
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:590