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>
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()); }
153 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>
203 virtual void newTree() = 0;
208 virtual bool empty()
const = 0;
210 virtual void clear() = 0;
221 virtual void pruneGrid(
float tolerance = 0.0) = 0;
227 void clipGrid(
const BBoxd&);
261 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&)
const;
262 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&);
263 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&)
const;
264 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&);
271 std::string getName()
const;
273 void setName(
const std::string&);
276 std::string getCreator()
const;
278 void setCreator(
const std::string&);
282 bool saveFloatAsHalf()
const;
283 void setSaveFloatAsHalf(
bool);
294 void clearGridClass();
299 static std::string gridClassToString(
GridClass);
301 static std::string gridClassToMenuName(
GridClass);
306 static GridClass stringToGridClass(
const std::string&);
320 void clearVectorType();
325 static std::string vecTypeToString(
VecType);
328 static std::string vecTypeExamples(
VecType);
331 static std::string vecTypeDescription(
VecType);
332 static VecType stringToVecType(
const std::string&);
340 bool isInWorldSpace()
const;
342 void setIsInWorldSpace(
bool);
368 virtual Index64 activeVoxelCount()
const = 0;
372 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
375 virtual Coord evalActiveVoxelDim()
const = 0;
378 virtual Index64 memUsage()
const = 0;
384 void addStatsMetadata();
450 virtual void readTopology(std::istream&) = 0;
453 virtual void writeTopology(std::ostream&)
const = 0;
456 virtual void readBuffers(std::istream&) = 0;
458 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
464 virtual void readNonresidentBuffers()
const = 0;
466 virtual void writeBuffers(std::ostream&)
const = 0;
474 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
481 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
483 #if OPENVDB_ABI_VERSION_NUMBER >= 7 496 static void registerGrid(
const Name& type, GridFactory);
498 static void unregisterGrid(
const Name& type);
539 template<
typename Gr
idPtrContainerT>
540 inline typename GridPtrContainerT::value_type
543 using GridPtrT =
typename GridPtrContainerT::value_type;
544 typename GridPtrContainerT::const_iterator it =
545 std::find_if(container.begin(), container.end(),
GridNamePred(name));
546 return (it == container.end() ? GridPtrT() : *it);
550 template<
typename KeyT,
typename Gr
idPtrT>
554 using GridPtrMapT = std::map<KeyT, GridPtrT>;
555 for (
typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
558 const GridPtrT& grid = it->second;
559 if (grid && grid->getName() == name)
return grid;
570 template<
typename _TreeType>
601 template<
typename OtherValueType>
633 template<
typename OtherTreeType>
644 Grid& operator=(
const Grid&) =
delete;
654 ConstPtr copy()
const;
657 Ptr copyWithNewTree()
const;
673 #if OPENVDB_ABI_VERSION_NUMBER >= 7 674 ConstPtr copyReplacingMetadata(
const MetaMap& meta)
const;
685 ConstPtr copyReplacingMetadataAndTransform(
const MetaMap& meta,
712 Name type()
const override {
return this->gridType(); }
728 bool empty()
const override {
return tree().empty(); }
730 void clear()
override { tree().clear(); }
789 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
798 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
806 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
809 void pruneGrid(
float tolerance = 0.0)
override;
837 template<
typename OtherTreeType>
852 template<
typename OtherTreeType>
865 template<
typename OtherTreeType>
876 CoordBBox evalActiveVoxelBoundingBox()
const override;
878 Coord evalActiveVoxelDim()
const override;
880 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
893 TreePtrType treePtr() {
return mTree; }
901 TreeType& tree() {
return *mTree; }
924 void newTree()
override;
934 void readTopology(std::istream&)
override;
937 void writeTopology(std::ostream&)
const override;
940 void readBuffers(std::istream&)
override;
942 void readBuffers(std::istream&,
const CoordBBox&)
override;
948 void readNonresidentBuffers()
const override;
950 void writeBuffers(std::ostream&)
const override;
953 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
960 static inline bool hasMultiPassIO();
974 <<
" might not be threadsafe on this platform");
984 #if OPENVDB_ABI_VERSION_NUMBER >= 7 1006 template<
typename Gr
idType>
1007 inline typename GridType::Ptr
1010 return GridBase::grid<GridType>(grid);
1022 template<
typename Gr
idType>
1023 inline typename GridType::ConstPtr
1026 return GridBase::constGrid<GridType>(grid);
1039 template<
typename Gr
idType>
1040 inline typename GridType::Ptr
1043 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
1044 return gridPtrCast<GridType>(grid->deepCopyGrid());
1048 template<
typename Gr
idType>
1049 inline typename GridType::Ptr
1052 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
1062 template<
typename _TreeType>
1094 template<
typename _TreeType>
1123 template<
typename _TreeType>
1164 template<
typename LeafNodeType>
1166 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1170 template<
typename RootNodeType>
1177 template<
typename TreeType>
1186 #if OPENVDB_ABI_VERSION_NUMBER >= 7 1195 template<
typename Gr
idType>
1196 inline typename GridType::Ptr
1201 if (
grid &&
grid->type() == GridType::gridType()) {
1202 return StaticPtrCast<GridType>(
grid);
1204 return typename GridType::Ptr();
1208 template<
typename Gr
idType>
1209 inline typename GridType::ConstPtr
1212 return ConstPtrCast<const GridType>(
1213 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1217 template<
typename Gr
idType>
1218 inline typename GridType::ConstPtr
1221 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(
grid));
1225 template<
typename Gr
idType>
1226 inline typename GridType::ConstPtr
1229 return ConstPtrCast<const GridType>(
1230 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1252 template<
typename TreeT>
1258 template<
typename TreeT>
1264 template<
typename TreeT>
1271 #if OPENVDB_ABI_VERSION_NUMBER >= 7 1272 template<
typename TreeT>
1282 template<
typename TreeT>
1290 template<
typename TreeT>
1291 template<
typename OtherTreeType>
1294 mTree(new
TreeType(other.constTree()))
1299 template<
typename TreeT>
1307 template<
typename TreeT>
1316 template<
typename TreeT>
1325 template<
typename TreeT>
1329 return Ptr(
new Grid(background));
1334 template<
typename TreeT>
1343 template<
typename TreeT>
1354 template<
typename TreeT>
1362 #if OPENVDB_ABI_VERSION_NUMBER >= 7 1363 template<
typename TreeT>
1368 this->constTransformPtr());
1369 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1373 template<
typename TreeT>
1377 return this->copyReplacingMetadataAndTransform(*
this, xform);
1380 template<
typename TreeT>
1385 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1391 template<
typename TreeT>
1399 template<
typename TreeT>
1409 template<
typename TreeT>
1413 return this->copy();
1416 template<
typename TreeT>
1420 return this->copy();
1423 #if OPENVDB_ABI_VERSION_NUMBER >= 7 1424 template<
typename TreeT>
1428 return this->copyReplacingMetadata(meta);
1431 template<
typename TreeT>
1435 return this->copyReplacingTransform(xform);
1438 template<
typename TreeT>
1443 return this->copyReplacingMetadataAndTransform(meta, xform);
1447 template<
typename TreeT>
1451 return this->copyWithNewTree();
1458 template<
typename TreeT>
1463 if (tree->type() != TreeType::treeType()) {
1465 + tree->type() +
" to a grid of type " + this->type());
1467 mTree = StaticPtrCast<TreeType>(tree);
1471 template<
typename TreeT>
1475 mTree.reset(
new TreeType(this->background()));
1482 template<
typename TreeT>
1486 tree().sparseFill(bbox, value, active);
1490 template<
typename TreeT>
1494 this->sparseFill(bbox, value, active);
1497 template<
typename TreeT>
1501 tree().denseFill(bbox, value, active);
1504 template<
typename TreeT>
1509 const auto value = zeroVal<ValueType>() + tolerance;
1511 this->tree().prune(static_cast<ValueType>(value));
1514 template<
typename TreeT>
1521 template<
typename TreeT>
1525 tree().merge(other.
tree(), policy);
1529 template<
typename TreeT>
1530 template<
typename OtherTreeType>
1534 tree().topologyUnion(other.
tree());
1538 template<
typename TreeT>
1539 template<
typename OtherTreeType>
1543 tree().topologyIntersection(other.
tree());
1547 template<
typename TreeT>
1548 template<
typename OtherTreeType>
1552 tree().topologyDifference(other.
tree());
1559 template<
typename TreeT>
1563 tree().evalMinMax(minVal, maxVal);
1567 template<
typename TreeT>
1572 tree().evalActiveVoxelBoundingBox(bbox);
1577 template<
typename TreeT>
1582 const bool nonempty = tree().evalActiveVoxelDim(dim);
1583 return (nonempty ? dim :
Coord());
1593 template<
typename TreeT>
1597 tree().readTopology(is, saveFloatAsHalf());
1601 template<
typename TreeT>
1605 tree().writeTopology(os, saveFloatAsHalf());
1609 template<
typename TreeT>
1614 tree().readBuffers(is, saveFloatAsHalf());
1616 uint16_t numPasses = 1;
1617 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1620 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1621 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1622 meta->setPass(pass);
1623 tree().readBuffers(is, saveFloatAsHalf());
1631 template<
typename TreeT>
1636 tree().readBuffers(is, bbox, saveFloatAsHalf());
1638 uint16_t numPasses = 1;
1639 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1642 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1643 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1644 meta->setPass(pass);
1645 tree().readBuffers(is, saveFloatAsHalf());
1654 template<
typename TreeT>
1658 tree().readNonresidentBuffers();
1662 template<
typename TreeT>
1666 if (!hasMultiPassIO()) {
1667 tree().writeBuffers(os, saveFloatAsHalf());
1672 uint16_t numPasses = 1;
1673 meta->setCountingPasses(
true);
1675 tree().writeBuffers(os, saveFloatAsHalf());
1676 numPasses = static_cast<uint16_t>(meta->pass());
1677 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1678 meta->setCountingPasses(
false);
1681 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1682 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1683 meta->setPass(pass);
1684 tree().writeBuffers(os, saveFloatAsHalf());
1691 template<
typename TreeT>
1699 template<
typename TreeT>
1703 tree().print(os, verboseLevel);
1705 if (metaCount() > 0) {
1706 os <<
"Additional metadata:" << std::endl;
1708 os <<
" " << it->first;
1710 const std::string value = it->second->str();
1711 if (!value.empty()) os <<
": " << value;
1717 os <<
"Transform:" << std::endl;
1718 transform().print(os,
" ");
1726 template<
typename Gr
idType>
1727 inline typename GridType::Ptr
1730 return GridType::create(background);
1734 template<
typename Gr
idType>
1735 inline typename GridType::Ptr
1738 return GridType::create();
1742 template<
typename TreePtrType>
1746 using TreeType =
typename TreePtrType::element_type;
1751 template<
typename Gr
idType>
1752 typename GridType::Ptr
1755 using ValueType =
typename GridType::ValueType;
1758 static_assert(std::is_floating_point<ValueType>::value,
1759 "level-set grids must be floating-point-valued");
1761 typename GridType::Ptr grid = GridType::create(
1762 static_cast<ValueType>(voxelSize * halfWidth));
1772 namespace internal {
1775 template<
typename OpT,
typename GridBaseT,
typename T,
typename ...Ts>
1776 struct GridApplyImpl {
static bool apply(GridBaseT&, OpT&) {
return false; } };
1780 template<
typename OpT,
typename GridBaseT,
typename GridT,
typename ...GridTs>
1781 struct GridApplyImpl<OpT, GridBaseT,
TypeList<GridT, GridTs...>>
1783 static bool apply(GridBaseT& grid, OpT& op)
1785 if (grid.template isType<GridT>()) {
1789 return GridApplyImpl<OpT, GridBaseT,
TypeList<GridTs...>>::apply(grid, op);
1796 template<
typename Gr
idTypeListT,
typename OpT>
1800 return internal::GridApplyImpl<OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1803 template<
typename Gr
idTypeListT,
typename OpT>
1807 return internal::GridApplyImpl<OpT, GridBase, GridTypeListT>::apply(*
this, op);
1810 template<
typename Gr
idTypeListT,
typename OpT>
1814 return internal::GridApplyImpl<const OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1817 template<
typename Gr
idTypeListT,
typename OpT>
1821 return internal::GridApplyImpl<const OpT, GridBase, GridTypeListT>::apply(*
this, op);
1827 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:521
_TreeType TreeType
Definition: Grid.h:1097
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:978
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:588
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1068
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:706
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:1603
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1130
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:357
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:353
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:460
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:481
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:412
static TreeType & tree(TreeType &t)
Definition: Grid.h:1112
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1516
Definition: ValueAccessor.h:193
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:1532
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:471
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:967
Abstract base class for typed grids.
Definition: Grid.h:77
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
Definition: Grid.h:440
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1117
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:510
static const char *const META_GRID_NAME
Definition: Grid.h:352
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:762
Vec3< double > Vec3d
Definition: Vec3.h:662
SharedPtr< Grid > Ptr
Definition: Grid.h:574
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:743
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1108
GridNamePred(const Name &_name)
Definition: Grid.h:533
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:712
Name name
Definition: Grid.h:535
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1139
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1087
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1100
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:584
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:704
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1135
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:717
GridBase(GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:493
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:1426
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1569
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1134
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
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:1440
std::string Name
Definition: Name.h:17
std::shared_ptr< T > SharedPtr
Definition: Types.h:91
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,...
Definition: Grid.h:1433
typename TreeType::ValueType ValueType
Definition: Grid.h:1077
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:187
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:1024
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1579
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1115
static TreeType & tree(GridType &g)
Definition: Grid.h:1083
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:906
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1080
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:586
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1088
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:411
Base class for typed trees.
Definition: Tree.h:35
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:896
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:403
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1116
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1253
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1664
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:760
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:1008
static TreeType & tree(TreeType &t)
Definition: Grid.h:1141
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1506
Ptr(*)() GridFactory
Definition: Grid.h:83
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:1050
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:359
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:1401
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1137
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1098
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1078
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:25
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:1411
static const char *const META_GRID_CLASS
Definition: Grid.h:350
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:519
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:745
double Real
Definition: Types.h:37
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:490
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1076
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:1393
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:1484
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1318
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:511
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:1492
~GridBase() override
Definition: Grid.h:86
~Grid() override
Definition: Grid.h:641
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1114
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:123
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1070
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1099
static TreeType & tree(GridType &g)
Definition: Grid.h:1113
static const char *const META_VECTOR_TYPE
Definition: Grid.h:355
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:1449
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:592
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:583
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:182
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:602
Definition: Exceptions.h:65
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1165
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:429
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:758
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:39
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:356
static TreeType & tree(GridType &g)
Definition: Grid.h:1142
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:1365
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:148
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:1753
typename std::remove_const< ToType >::type Type
Definition: Types.h:298
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1127
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:516
SharedPtr< TreeBase > Ptr
Definition: Tree.h:38
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
typename GridType::Ptr GridPtrType
Definition: Grid.h:1074
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:512
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:527
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:534
static const char *const META_GRID_CREATOR
Definition: Grid.h:351
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:358
_TreeType TreeType
Definition: Grid.h:577
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:905
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1460
tree::TreeBase TreeBase
Definition: Grid.h:26
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:522
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...
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:1798
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:768
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1065
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:755
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:1382
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:587
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:575
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1473
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:728
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:354
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1069
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:735
Definition: Exceptions.h:13
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:1219
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:579
void topologyIntersection(const Grid< OtherTreeType > &other)
Intersect this grid's set of active values with the active values of the other grid,...
Definition: Grid.h:1541
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:515
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:770
MergePolicy
Definition: Types.h:505
typename _TreeType::ValueType ValueType
Definition: Grid.h:580
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1701
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:730
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:874
VecType
Definition: Types.h:482
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:897
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:590
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:772
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:434
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1728
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1146
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:509
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:432
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1079
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:1595
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1561
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1144
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1118
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:1656
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:1197
void topologyDifference(const Grid< OtherTreeType > &other)
Difference this grid's set of active values with the active values of the other grid,...
Definition: Grid.h:1550
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1150
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
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:591
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:526
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1148
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 ...
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:766
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1101
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:552
static TreeType & tree(TreeType &t)
Definition: Grid.h:1082
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers.
Definition: Grid.h:1693
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1523
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:514
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1119
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:28
virtual TreeBase::ConstPtr constBaseTreePtr() const =0
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1105
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:438
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1143
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:248
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1138
Definition: version.h:198
A list of types (not necessarily unique)
Definition: Types.h:389
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,...
Definition: Grid.h:1375
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:469
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:774
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:1235
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:1499
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1086
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:192
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
typename _TreeType::BuildType BuildType
Definition: Grid.h:581
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:714
typename TreeType::ValueType ValueType
Definition: Grid.h:1107
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1075
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:360
uint64_t Index64
Definition: Types.h:30
_TreeType TreeType
Definition: Grid.h:1126
GridClass
Definition: Types.h:452
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1149
typename TreeType::ValueType ValueType
Definition: Grid.h:1136
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:520
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:764
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:525
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:517
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:907
Index64 memUsage() const override
Definition: Grid.h:884
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1611
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:524
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:593
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1089
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1147
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1106
Definition: LeafBuffer.h:40
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:578
typename GridType::Ptr GridPtrType
Definition: Grid.h:1104
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1110
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:531
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1128
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:747
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1085
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1744
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:969
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:436
_TreeType TreeType
Definition: Grid.h:1067
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1084
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:585
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1109
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:725
Definition: Exceptions.h:64
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:402
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform.
Definition: Grid.h:1242
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1071
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:898
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1145
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:678
typename GridType::Ptr GridPtrType
Definition: Grid.h:1133
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1129
static const char *const META_FILE_DELAYED_LOAD
Definition: Grid.h:361