31 #ifndef OPENVDB_GRID_HAS_BEEN_INCLUDED 32 #define OPENVDB_GRID_HAS_BEEN_INCLUDED 45 #include <type_traits> 55 template<
typename>
class Grid;
62 template<
typename Gr
idType>
63 inline typename GridType::Ptr
createGrid(
const typename GridType::ValueType& background);
69 template<
typename Gr
idType>
77 template<
typename TreePtrType>
95 template<
typename Gr
idType>
119 #if OPENVDB_ABI_VERSION_NUMBER <= 3 148 static bool isRegistered(
const Name &type);
151 static void clearRegistry();
159 virtual Name type()
const = 0;
161 virtual Name valueType()
const = 0;
164 template<
typename Gr
idType>
165 bool isType()
const {
return (this->type() == GridType::gridType()); }
170 template<
typename Gr
idType>
174 template<
typename Gr
idType>
176 template<
typename Gr
idType>
177 static typename GridType::ConstPtr constGrid(
const GridBase::Ptr&);
178 template<
typename Gr
idType>
220 virtual void newTree() = 0;
225 virtual bool empty()
const = 0;
227 virtual void clear() = 0;
238 virtual void pruneGrid(
float tolerance = 0.0) = 0;
240 #if OPENVDB_ABI_VERSION_NUMBER >= 3 241 void clipGrid(
const BBoxd&);
280 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&)
const;
281 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&);
282 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&)
const;
283 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&);
290 std::string getName()
const;
292 void setName(
const std::string&);
295 std::string getCreator()
const;
297 void setCreator(
const std::string&);
301 bool saveFloatAsHalf()
const;
302 void setSaveFloatAsHalf(
bool);
313 void clearGridClass();
318 static std::string gridClassToString(
GridClass);
320 static std::string gridClassToMenuName(
GridClass);
325 static GridClass stringToGridClass(
const std::string&);
339 void clearVectorType();
344 static std::string vecTypeToString(
VecType);
347 static std::string vecTypeExamples(
VecType);
350 static std::string vecTypeDescription(
VecType);
351 static VecType stringToVecType(
const std::string&);
359 bool isInWorldSpace()
const;
361 void setIsInWorldSpace(
bool);
387 virtual Index64 activeVoxelCount()
const = 0;
391 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
394 virtual Coord evalActiveVoxelDim()
const = 0;
397 virtual Index64 memUsage()
const = 0;
403 void addStatsMetadata();
469 virtual void readTopology(std::istream&) = 0;
472 virtual void writeTopology(std::ostream&)
const = 0;
475 virtual void readBuffers(std::istream&) = 0;
476 #if OPENVDB_ABI_VERSION_NUMBER >= 3 477 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
484 virtual void readNonresidentBuffers()
const = 0;
486 virtual void writeBuffers(std::ostream&)
const = 0;
495 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
502 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
507 #if OPENVDB_ABI_VERSION_NUMBER <= 3 513 GridBase(GridBase& other,
ShallowCopy):
MetaMap(other), mTransform(other.mTransform) {}
520 static void unregisterGrid(
const Name& type);
561 template<
typename Gr
idPtrContainerT>
562 inline typename GridPtrContainerT::value_type
565 using GridPtrT =
typename GridPtrContainerT::value_type;
566 typename GridPtrContainerT::const_iterator it =
567 std::find_if(container.begin(), container.end(),
GridNamePred(name));
568 return (it == container.end() ? GridPtrT() : *it);
572 template<
typename KeyT,
typename Gr
idPtrT>
576 using GridPtrMapT = std::map<KeyT, GridPtrT>;
577 for (
typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
580 const GridPtrT& grid = it->second;
581 if (grid && grid->getName() == name)
return grid;
592 template<
typename _TreeType>
623 template<
typename OtherValueType>
655 template<
typename OtherTreeType>
657 #if OPENVDB_ABI_VERSION_NUMBER <= 3 672 Grid& operator=(
const Grid&) =
delete;
675 #if OPENVDB_ABI_VERSION_NUMBER <= 3 699 Ptr copyWithNewTree()
const;
724 Name type()
const override {
return this->gridType(); }
740 bool empty()
const override {
return tree().empty(); }
742 void clear()
override { tree().clear(); }
821 void pruneGrid(
float tolerance = 0.0)
override;
823 #if OPENVDB_ABI_VERSION_NUMBER >= 3 851 template<
typename OtherTreeType>
866 template<
typename OtherTreeType>
879 template<
typename OtherTreeType>
890 CoordBBox evalActiveVoxelBoundingBox()
const override;
892 Coord evalActiveVoxelDim()
const override;
938 void newTree()
override;
948 void readTopology(std::istream&)
override;
951 void writeTopology(std::ostream&)
const override;
954 void readBuffers(std::istream&)
override;
955 #if OPENVDB_ABI_VERSION_NUMBER >= 3 956 void readBuffers(std::istream&,
const CoordBBox&)
override;
963 void readNonresidentBuffers()
const override;
965 void writeBuffers(std::ostream&)
const override;
969 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
976 static inline bool hasMultiPassIO();
990 <<
" might not be threadsafe on this platform");
1017 template<
typename Gr
idType>
1018 inline typename GridType::Ptr
1021 return GridBase::grid<GridType>(grid);
1033 template<
typename Gr
idType>
1034 inline typename GridType::ConstPtr
1037 return GridBase::constGrid<GridType>(grid);
1050 template<
typename Gr
idType>
1051 inline typename GridType::Ptr
1054 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
1055 return gridPtrCast<GridType>(grid->deepCopyGrid());
1059 template<
typename Gr
idType>
1060 inline typename GridType::Ptr
1063 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
1073 template<
typename _TreeType>
1105 template<
typename _TreeType>
1134 template<
typename _TreeType>
1175 template<
typename LeafNodeType>
1177 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1181 template<
typename RootNodeType>
1188 template<
typename TreeType>
1198 template<
typename Gr
idType>
1199 inline typename GridType::Ptr
1204 if (grid && grid->type() == GridType::gridType()) {
1205 return StaticPtrCast<GridType>(grid);
1207 return typename GridType::Ptr();
1211 template<
typename Gr
idType>
1212 inline typename GridType::ConstPtr
1215 return ConstPtrCast<const GridType>(
1216 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1220 template<
typename Gr
idType>
1221 inline typename GridType::ConstPtr
1224 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(grid));
1228 template<
typename Gr
idType>
1229 inline typename GridType::ConstPtr
1232 return ConstPtrCast<const GridType>(
1233 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1240 return ConstPtrCast<TreeBase>(this->constBaseTreePtr());
1255 template<
typename TreeT>
1261 template<
typename TreeT>
1267 template<
typename TreeT>
1274 template<
typename TreeT>
1282 template<
typename TreeT>
1283 template<
typename OtherTreeType>
1291 #if OPENVDB_ABI_VERSION_NUMBER <= 3 1292 template<
typename TreeT>
1299 template<
typename TreeT>
1308 template<
typename TreeT>
1317 template<
typename TreeT>
1326 template<
typename TreeT>
1330 return Ptr(
new Grid(background));
1335 template<
typename TreeT>
1344 template<
typename TreeT>
1355 #if OPENVDB_ABI_VERSION_NUMBER <= 3 1357 template<
typename TreeT>
1362 switch (treePolicy) {
1368 ret.reset(
new Grid(*
this));
1378 template<
typename TreeT>
1382 return this->
copy(treePolicy);
1385 #else // if OPENVDB_ABI_VERSION_NUMBER > 3 1387 template<
typename TreeT>
1394 template<
typename TreeT>
1402 template<
typename TreeT>
1412 template<
typename TreeT>
1416 return this->
copy();
1419 template<
typename TreeT>
1423 return this->
copy();
1427 template<
typename TreeT>
1440 template<
typename TreeT>
1445 if (tree->type() != TreeType::treeType()) {
1447 + tree->type() +
" to a grid of type " + this->
type());
1449 mTree = StaticPtrCast<TreeType>(
tree);
1453 template<
typename TreeT>
1464 template<
typename TreeT>
1468 tree().sparseFill(bbox, value, active);
1472 template<
typename TreeT>
1479 template<
typename TreeT>
1483 tree().denseFill(bbox, value, active);
1486 template<
typename TreeT>
1491 const auto value = zeroVal<ValueType>() + tolerance;
1493 this->
tree().prune(static_cast<ValueType>(value));
1496 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1497 template<
typename TreeT>
1506 template<
typename TreeT>
1510 tree().merge(other.
tree(), policy);
1514 template<
typename TreeT>
1515 template<
typename OtherTreeType>
1519 tree().topologyUnion(other.
tree());
1523 template<
typename TreeT>
1524 template<
typename OtherTreeType>
1528 tree().topologyIntersection(other.
tree());
1532 template<
typename TreeT>
1533 template<
typename OtherTreeType>
1537 tree().topologyDifference(other.
tree());
1544 template<
typename TreeT>
1548 tree().evalMinMax(minVal, maxVal);
1552 template<
typename TreeT>
1557 tree().evalActiveVoxelBoundingBox(bbox);
1562 template<
typename TreeT>
1567 const bool nonempty =
tree().evalActiveVoxelDim(dim);
1568 return (nonempty ? dim :
Coord());
1578 template<
typename TreeT>
1586 template<
typename TreeT>
1594 template<
typename TreeT>
1601 uint16_t numPasses = 1;
1602 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1605 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1606 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1607 meta->setPass(pass);
1614 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1618 template<
typename TreeT>
1625 uint16_t numPasses = 1;
1626 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1629 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1630 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1631 meta->setPass(pass);
1641 template<
typename TreeT>
1645 tree().readNonresidentBuffers();
1651 template<
typename TreeT>
1661 uint16_t numPasses = 1;
1662 meta->setCountingPasses(
true);
1665 numPasses =
static_cast<uint16_t
>(meta->pass());
1666 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1667 meta->setCountingPasses(
false);
1670 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1671 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1672 meta->setPass(pass);
1680 template<
typename TreeT>
1688 template<
typename TreeT>
1692 tree().print(os, verboseLevel);
1695 os <<
"Additional metadata:" << std::endl;
1697 os <<
" " << it->first;
1699 const std::string value = it->second->str();
1700 if (!value.empty()) os <<
": " << value;
1706 os <<
"Transform:" << std::endl;
1715 template<
typename Gr
idType>
1716 inline typename GridType::Ptr
1719 return GridType::create(background);
1723 template<
typename Gr
idType>
1724 inline typename GridType::Ptr
1727 return GridType::create();
1731 template<
typename TreePtrType>
1735 using TreeType =
typename TreePtrType::element_type;
1740 template<
typename Gr
idType>
1741 typename GridType::Ptr
1744 using ValueType =
typename GridType::ValueType;
1747 static_assert(std::is_floating_point<ValueType>::value,
1748 "level-set grids must be floating-point-valued");
1750 typename GridType::Ptr
grid = GridType::create(
1751 static_cast<ValueType>(voxelSize * halfWidth));
1761 namespace internal {
1764 template<
typename OpT,
typename GridBaseT,
typename T,
typename ...Ts>
1765 struct GridApplyImpl {
static bool apply(GridBaseT&, OpT&) {
return false; } };
1769 template<
typename OpT,
typename GridBaseT,
typename GridT,
typename ...GridTs>
1770 struct GridApplyImpl<OpT, GridBaseT, TypeList<GridT, GridTs...>>
1772 static bool apply(GridBaseT&
grid, OpT& op)
1774 if (grid.template isType<GridT>()) {
1778 return GridApplyImpl<OpT, GridBaseT, TypeList<GridTs...>>
::apply(grid, op);
1785 template<
typename Gr
idTypeListT,
typename OpT>
1789 return internal::GridApplyImpl<OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1792 template<
typename Gr
idTypeListT,
typename OpT>
1796 return internal::GridApplyImpl<OpT, GridBase, GridTypeListT>::apply(*
this, op);
1799 template<
typename Gr
idTypeListT,
typename OpT>
1803 return internal::GridApplyImpl<const OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1806 template<
typename Gr
idTypeListT,
typename OpT>
1810 return internal::GridApplyImpl<const OpT, GridBase, GridTypeListT>::apply(*
this, op);
1816 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1081
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:378
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1161
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1128
typename GridType::Ptr GridPtrType
Definition: Grid.h:1115
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 ...
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:742
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:888
typename TreeType::ValueType ValueType
Definition: Grid.h:1147
_TreeType TreeType
Definition: Grid.h:599
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1096
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:919
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:376
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1442
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:1526
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1119
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1155
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:782
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:539
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:502
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1125
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1091
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1455
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:740
static const char *const META_FILE_DELAYED_LOAD
Definition: Grid.h:380
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:492
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:747
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1160
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:534
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:784
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:1535
OPENVDB_API uint32_t getGridClass(std::ios_base &)
Return the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently being read from or writte...
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:613
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:597
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1097
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:778
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1157
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:372
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
Definition: Grid.h:1682
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:533
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
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:1238
static TreeType & tree(GridType &g)
Definition: Grid.h:1094
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:431
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:601
static TreeType & tree(GridType &g)
Definition: Grid.h:1153
GridNamePred(const Name &_name)
Definition: Grid.h:555
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:546
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:911
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1117
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:548
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:532
static TreeType & tree(TreeType &t)
Definition: Grid.h:1152
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:612
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:52
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1508
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1129
typename _TreeType::ValueType ValueType
Definition: Grid.h:602
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:448
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1690
static const char *const META_GRID_NAME
Definition: Grid.h:371
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1145
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:1580
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:556
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1121
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1158
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:510
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:421
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1141
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:422
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1120
~GridBase() override
Definition: Grid.h:113
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1095
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:1787
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:375
typename _TreeType::BuildType BuildType
Definition: Grid.h:603
Definition: LeafBuffer.h:67
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:776
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:373
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1546
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1100
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:747
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:1643
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:537
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
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:171
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:600
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:1035
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:786
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:209
_TreeType TreeType
Definition: Grid.h:1078
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:985
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
Vec3< double > Vec3d
Definition: Vec3.h:689
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:543
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:204
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:912
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:531
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:1481
Name name
Definition: Grid.h:557
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1080
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:541
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:726
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:451
double Real
Definition: Types.h:67
MergePolicy
Definition: Types.h:555
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:505
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1089
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:544
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:921
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1090
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1112
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:718
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:615
typename std::remove_const< ToType >::type Type
Definition: Types.h:348
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1082
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:128
typename GridType::Ptr GridPtrType
Definition: Grid.h:1144
Definition: Exceptions.h:91
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1130
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
std::string Name
Definition: Name.h:44
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:379
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:429
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:1061
static const char *const META_GRID_CLASS
Definition: Grid.h:369
Index64 memUsage() const override
Definition: Grid.h:898
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1596
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1146
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1111
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:542
typename GridType::Ptr GridPtrType
Definition: Grid.h:1085
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:737
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:280
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:983
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1126
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1148
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:275
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:759
typename TreeType::ValueType ValueType
Definition: Grid.h:1118
tree::TreeBase TreeBase
Definition: Grid.h:53
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels...
Definition: Grid.h:755
static const char *const META_VECTOR_TYPE
Definition: Grid.h:374
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:1517
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:607
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1098
Definition: Exceptions.h:40
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:610
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:457
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
Definition: Grid.h:459
GridClass
Definition: Types.h:502
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1127
static TreeType & tree(TreeType &t)
Definition: Grid.h:1093
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:729
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1079
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:377
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1109
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:574
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:490
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:724
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:606
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:716
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:994
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:190
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:165
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:1588
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:624
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1156
VecType
Definition: Types.h:532
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1554
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:553
uint64_t Index64
Definition: Types.h:60
Abstract base class for typed grids.
Definition: Grid.h:104
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:199
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1140
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1099
static TreeType & tree(GridType &g)
Definition: Grid.h:1124
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1087
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1499
SharedPtr< Grid > Ptr
Definition: Grid.h:596
Base class for typed trees.
Definition: Tree.h:62
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:547
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1116
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:910
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:1200
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1653
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:757
_TreeType TreeType
Definition: Grid.h:1108
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:774
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
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:1742
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:1466
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:1222
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:1404
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1564
static TreeType & tree(TreeType &t)
Definition: Grid.h:1123
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:920
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:430
Definition: ValueAccessor.h:220
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1154
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:608
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1256
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1319
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1245
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:772
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1149
Ptr(*)() GridFactory
Definition: Grid.h:110
typename TreeType::ValueType ValueType
Definition: Grid.h:1088
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1138
Definition: version.h:224
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:536
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1159
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:455
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:549
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:453
Definition: Exceptions.h:92
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:1019
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1488
SharedPtr< TreeBase > Ptr
Definition: Tree.h:65
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1076
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:66
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:1474
~Grid() override
Definition: Grid.h:669
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1110
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:1414
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1150
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:538
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:614
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:1396
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1176
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1086
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:609
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1139
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:770
_TreeType TreeType
Definition: Grid.h:1137
static const char *const META_GRID_CREATOR
Definition: Grid.h:370
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1733
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:108
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:1429
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:605
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:780
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:767