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 (*)();
129 static bool isRegistered(
const Name &type);
132 static void clearRegistry();
140 virtual Name type()
const = 0;
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&);
234 virtual void clip(
const CoordBBox&) = 0;
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&);
272 std::string getName()
const;
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;
385 void addStatsMetadata();
430 Vec3d
voxelSize()
const {
return transform().voxelSize(); }
433 Vec3d
voxelSize(
const Vec3d& xyz)
const {
return transform().voxelSize(xyz); }
437 Vec3d
indexToWorld(
const Vec3d& xyz)
const {
return transform().indexToWorld(xyz); }
439 Vec3d
indexToWorld(
const Coord& ijk)
const {
return transform().indexToWorld(ijk); }
441 Vec3d
worldToIndex(
const Vec3d& xyz)
const {
return transform().worldToIndex(xyz); }
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>
539 inline typename GridPtrContainerT::value_type
542 using GridPtrT =
typename GridPtrContainerT::value_type;
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>
600 template<
typename OtherValueType>
632 template<
typename OtherTreeType>
643 Grid& operator=(
const Grid&) =
delete;
656 Ptr copyWithNewTree()
const;
709 Name type()
const override {
return this->gridType(); }
725 bool empty()
const override {
return tree().empty(); }
727 void clear()
override { tree().clear(); }
786 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
795 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
803 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
806 void pruneGrid(
float tolerance = 0.0)
override;
812 void clip(
const CoordBBox&)
override;
834 template<
typename OtherTreeType>
849 template<
typename OtherTreeType>
862 template<
typename OtherTreeType>
873 CoordBBox evalActiveVoxelBoundingBox()
const override;
875 Coord evalActiveVoxelDim()
const override;
878 tools::minMax(grid->tree()). Use threaded = false for serial execution")
901 bool isTreeUnique()
const final;
927 void newTree()
override;
937 void readTopology(std::istream&)
override;
940 void writeTopology(std::ostream&)
const override;
943 void readBuffers(std::istream&)
override;
945 void readBuffers(std::istream&,
const CoordBBox&)
override;
951 void readNonresidentBuffers()
const override;
953 void writeBuffers(std::ostream&)
const override;
956 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
963 static inline bool hasMultiPassIO();
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>
1195 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1199 template<
typename RootNodeType>
1206 template<
typename TreeType>
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)));
1279 template<
typename TreeT>
1285 template<
typename TreeT>
1291 template<
typename TreeT>
1298 template<
typename TreeT>
1307 template<
typename TreeT>
1315 template<
typename TreeT>
1316 template<
typename OtherTreeType>
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>
1397 template<
typename TreeT>
1404 template<
typename TreeT>
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>
1453 template<
typename TreeT>
1460 template<
typename TreeT>
1468 template<
typename TreeT>
1479 template<
typename TreeT>
1483 return mTree.use_count() == 1;
1487 template<
typename TreeT>
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>
1511 template<
typename TreeT>
1515 tree().sparseFill(bbox, value, active);
1519 template<
typename TreeT>
1526 template<
typename TreeT>
1530 tree().denseFill(bbox, value, active);
1533 template<
typename TreeT>
1537 const auto value =
math::cwiseAdd(zeroVal<ValueType>(), tolerance);
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>
1630 template<
typename TreeT>
1638 template<
typename TreeT>
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);
1660 template<
typename TreeT>
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);
1683 template<
typename TreeT>
1687 tree().readNonresidentBuffers();
1691 template<
typename TreeT>
1701 uint16_t numPasses = 1;
1702 meta->setCountingPasses(
true);
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);
1720 template<
typename TreeT>
1728 template<
typename TreeT>
1732 tree().print(os, verboseLevel);
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>
1775 using TreeType =
typename TreePtrType::element_type;
1780 template<
typename Gr
idType>
1781 typename GridType::Ptr
1784 using ValueType =
typename GridType::ValueType;
1787 static_assert(std::is_floating_point<ValueType>::value,
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 typename TreeType::Ptr TreePtrType
Definition: Grid.h:1151
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:1002
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: PointStatisticsImpl.h:498
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1153
_TreeType TreeType
Definition: Grid.h:1120
static NonConstTreeType & tree(NonConstGridType &g)
Definition: Grid.h:1165
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1070
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:1470
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:722
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1104
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:725
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:752
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:1568
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1502
typename TreeType::ValueType ValueType
Definition: Grid.h:1130
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:574
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:513
The Value Accessor Implementation and API methods. The majoirty of the API matches the API of a compa...
Definition: ValueAccessor.h:68
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1074
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:516
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:587
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1280
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:520
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Definition: Grid.h:1141
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:582
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:1262
math::Transform::Ptr transformPtr()
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:402
Definition: version.h.in:265
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:761
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:1632
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
Definition: Grid.h:1722
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:765
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1588
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels...
Definition: Grid.h:740
typename _TreeType::ValueType ValueType
Definition: Grid.h:579
uint64_t Index64
Definition: Types.h:53
auto cwiseAdd(const math::Vec3< math::half > &v, const float s)
Definition: Types.h:694
static const NonConstTreeType & constTree(const NonConstAccessorType &a)
Definition: Grid.h:1178
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1489
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Definition: Grid.h:1082
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1063
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
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1343
static NonConstTreeType & tree(NonConstTreeType &t)
Definition: Grid.h:1106
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1095
static const NonConstTreeType & tree(const NonConstGridType &g)
Definition: Grid.h:1169
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1543
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:551
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1100
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:742
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1640
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:1624
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1550
_TreeType TreeType
Definition: Grid.h:1091
Name name
Definition: Grid.h:534
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:703
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:583
OPENVDB_AX_API 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 GridType::Ptr GridPtrType
Definition: Grid.h:1068
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:1513
TreePtrType treePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:894
static NonConstTreeType & tree(NonConstGridType &g)
Definition: Grid.h:1077
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
static const NonConstTreeType & constTree(NonConstGridType &g)
Definition: Grid.h:1081
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:470
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1132
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1157
static const NonConstTreeType & constTree(const NonConstGridType &g)
Definition: Grid.h:1083
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:680
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:578
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:482
typename _TreeType::ConstUnsafeAccessor ConstUnsafeAccessor
Definition: Grid.h:592
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:732
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:509
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:511
static const NonConstTreeType & tree(const NonConstTreeType &t)
Definition: Grid.h:1168
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:769
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:514
static const char *const META_FILE_DELAYED_LOAD
Definition: Grid.h:362
static const char *const META_GRID_CREATOR
Definition: Grid.h:352
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...
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:871
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:1577
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:1224
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:413
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:1424
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:910
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1158
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:518
static const NonConstTreeType & constTree(const NonConstGridType &g)
Definition: Grid.h:1177
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:193
static const NonConstTreeType & constTree(NonConstGridType &g)
Definition: Grid.h:1111
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:354
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
_TreeType TreeType
Definition: Grid.h:1061
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:1406
static const char *const META_GRID_NAME
Definition: Grid.h:353
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:767
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:586
static NonConstTreeType & tree(NonConstTreeType &t)
Definition: Grid.h:1164
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:359
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:508
_TreeType TreeType
Definition: Grid.h:576
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1099
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:755
Definition: Exceptions.h:65
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:763
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:908
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:404
static const char *const META_VECTOR_TYPE
Definition: Grid.h:356
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:523
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1152
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1162
static NonConstTreeType & tree(NonConstTreeType &t)
Definition: Grid.h:1076
static const NonConstTreeType & tree(const NonConstTreeType &t)
Definition: Grid.h:1108
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1065
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:461
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:524
openvdb::GridBase Grid
Definition: Utils.h:34
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:1416
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:744
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:701
bool isTreeUnique() const final
Return true if tree is not shared with another grid.
Definition: Grid.h:1481
static const NonConstTreeType & tree(const ConstAccessorType &a)
Definition: Grid.h:1171
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:909
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:895
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
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:1399
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1730
typename _TreeType::UnsafeAccessor UnsafeAccessor
Definition: Grid.h:591
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1160
static NonConstTreeType & tree(NonConstGridType &g)
Definition: Grid.h:1136
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1059
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1693
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:1434
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:489
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:146
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Base class for typed trees.
Definition: Tree.h:37
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:510
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:521
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:711
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:1782
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:41
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1535
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1103
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:577
static const NonConstTreeType & tree(ConstAccessorType &a)
Definition: Grid.h:1167
bool empty(const char *str)
tests if a c-string str is empty, that is its first value is '\0'
Definition: Util.h:144
SharedPtr< Grid > Ptr
Definition: Grid.h:573
~GridBase() override
Definition: Grid.h:86
Definition: Exceptions.h:13
_TreeType TreeType
Definition: Grid.h:1149
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1062
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:358
static const NonConstTreeType & constTree(const NonConstGridType &g)
Definition: Grid.h:1142
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1122
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:435
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:533
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:709
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1069
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:360
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1194
static const NonConstTreeType & constTree(const ConstAccessorType &a)
Definition: Grid.h:1179
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:437
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1150
static const NonConstTreeType & tree(const NonConstTreeType &t)
Definition: Grid.h:1078
static const NonConstTreeType & tree(const NonConstGridType &g)
Definition: Grid.h:1138
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:430
tree::TreeBase TreeBase
Definition: Grid.h:26
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1131
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:585
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
double Real
Definition: Types.h:60
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Definition: Grid.h:1112
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:727
static const NonConstTreeType & constTree(NonConstGridType &g)
Definition: Grid.h:1140
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:1685
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:1246
static const NonConstTreeType & constTree(NonConstTreeType &t)
Definition: Grid.h:1172
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
static const NonConstTreeType & constTree(NonConstTreeType &t)
Definition: Grid.h:1080
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:525
typename tree::ValueAccessor< const NonConstTreeType > ConstAccessorType
Definition: Grid.h:1161
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:897
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1269
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1092
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:472
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:974
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:530
static NonConstTreeType & tree(NonConstTreeType &t)
Definition: Grid.h:1135
static const NonConstTreeType & tree(const NonConstGridType &g)
Definition: Grid.h:1109
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:403
typename GridType::Ptr GridPtrType
Definition: Grid.h:1098
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1129
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:433
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:183
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:1044
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:219
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:714
static const NonConstTreeType & tree(const NonConstTreeType &t)
Definition: Grid.h:1137
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
Definition: Grid.h:441
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:439
static NonConstTreeType & tree(NonConstAccessorType &a)
Definition: Grid.h:1166
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1073
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:188
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1133
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1123
MergePolicy
Definition: Types.h:506
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...
Definition: ValueAccessor.h:88
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1608
static NonConstTreeType & tree(NonConstGridType &g)
Definition: Grid.h:1107
GridBase(GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:492
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:1559
Index64 memUsage() const override
Definition: Grid.h:883
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 NonConstTreeType & constTree(NonConstGridType &g)
Definition: Grid.h:1173
static const char *const META_GRID_CLASS
Definition: Grid.h:351
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1124
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:355
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1121
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1093
static const NonConstTreeType & constTree(ConstAccessorType &a)
Definition: Grid.h:1175
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:970
Definition: Exceptions.h:64
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:412
GridNamePred(const Name &_name)
Definition: Grid.h:532
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 ...
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1128
typename TreeType::ValueType ValueType
Definition: Grid.h:1071
static const NonConstTreeType & constTree(const NonConstGridType &g)
Definition: Grid.h:1113
GridClass
Definition: Types.h:453
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Definition: Grid.h:1176
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:1448
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:171
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:357
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:771
~Grid() override
Definition: Grid.h:640
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1773
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1072
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
typename _TreeType::ConstAccessor ConstAccessor
Definition: Grid.h:590
typename TreeType::ValueType ValueType
Definition: Grid.h:1101
std::string Name
Definition: Name.h:19
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:1462
VecType
Definition: Types.h:483
static const NonConstTreeType & constTree(NonConstTreeType &t)
Definition: Grid.h:1139
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:411
typename GridType::Ptr GridPtrType
Definition: Grid.h:1156
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:1528
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1102
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1064
SharedPtr< TreeBase > Ptr
Definition: Tree.h:40
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:526
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
static const NonConstTreeType & tree(const NonConstAccessorType &a)
Definition: Grid.h:1170
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1598
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:1018
typename GridType::Ptr GridPtrType
Definition: Grid.h:1127
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:519
typename TreeType::ValueType ValueType
Definition: Grid.h:1159
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:1803
static const NonConstTreeType & constTree(NonConstAccessorType &a)
Definition: Grid.h:1174
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:896
static const NonConstTreeType & constTree(NonConstTreeType &t)
Definition: Grid.h:1110
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:1455
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:584
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:28
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:757
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:361
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:972
static const NonConstTreeType & tree(const NonConstGridType &g)
Definition: Grid.h:1079
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218
typename _TreeType::Accessor Accessor
Definition: Grid.h:589
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:759
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:1521
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:515
typename _TreeType::BuildType BuildType
Definition: Grid.h:580
Abstract base class for typed grids.
Definition: Grid.h:77
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1094
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:601
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:1389