31 #ifndef OPENVDB_GRID_HAS_BEEN_INCLUDED 32 #define OPENVDB_GRID_HAS_BEEN_INCLUDED 44 #include <type_traits> 54 template<
typename>
class Grid;
61 template<
typename Gr
idType>
62 inline typename GridType::Ptr
createGrid(
const typename GridType::ValueType& background);
68 template<
typename Gr
idType>
76 template<
typename TreePtrType>
94 template<
typename Gr
idType>
109 using GridFactory =
Ptr (*)();
114 #ifdef OPENVDB_3_ABI_COMPATIBLE 115 virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE)
const = 0;
140 static bool isRegistered(
const Name &type);
143 static void clearRegistry();
150 virtual Name type()
const = 0;
152 virtual Name valueType()
const = 0;
155 template<
typename Gr
idType>
156 bool isType()
const {
return (this->type() == GridType::gridType()); }
159 template<
typename Gr
idType>
163 template<
typename Gr
idType>
165 template<
typename Gr
idType>
166 static typename GridType::ConstPtr constGrid(
const GridBase::Ptr&);
167 template<
typename Gr
idType>
180 TreeBase& baseTree() {
return const_cast<TreeBase&
>(this->constBaseTree()); }
197 virtual void newTree() = 0;
200 virtual bool empty()
const = 0;
202 virtual void clear() = 0;
209 virtual void pruneGrid(
float tolerance = 0.0) = 0;
211 #ifndef OPENVDB_2_ABI_COMPATIBLE 212 void clipGrid(
const BBoxd&);
222 virtual void clip(
const CoordBBox&) = 0;
230 std::string getName()
const;
232 void setName(
const std::string&);
235 std::string getCreator()
const;
237 void setCreator(
const std::string&);
241 bool saveFloatAsHalf()
const;
242 void setSaveFloatAsHalf(
bool);
249 void clearGridClass();
252 static std::string gridClassToString(
GridClass);
254 static std::string gridClassToMenuName(
GridClass);
258 static GridClass stringToGridClass(
const std::string&);
267 void clearVectorType();
270 static std::string vecTypeToString(
VecType);
273 static std::string vecTypeExamples(
VecType);
276 static std::string vecTypeDescription(
VecType);
277 static VecType stringToVecType(
const std::string&);
282 bool isInWorldSpace()
const;
284 void setIsInWorldSpace(
bool);
307 virtual Index64 activeVoxelCount()
const = 0;
311 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
314 virtual Coord evalActiveVoxelDim()
const = 0;
317 virtual Index64 memUsage()
const = 0;
323 void addStatsMetadata();
365 Vec3d indexToWorld(
const Vec3d& xyz)
const {
return transform().indexToWorld(xyz); }
369 Vec3d worldToIndex(
const Vec3d& xyz)
const {
return transform().worldToIndex(xyz); }
378 virtual void readTopology(std::istream&) = 0;
381 virtual void writeTopology(std::ostream&)
const = 0;
384 virtual void readBuffers(std::istream&) = 0;
385 #ifndef OPENVDB_2_ABI_COMPATIBLE 386 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
393 virtual void readNonresidentBuffers()
const = 0;
395 virtual void writeBuffers(std::ostream&)
const = 0;
404 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
409 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
414 #ifdef OPENVDB_3_ABI_COMPATIBLE 423 static void registerGrid(
const Name& type, GridFactory);
425 static void unregisterGrid(
const Name& type);
466 template<
typename Gr
idPtrContainerT>
467 inline typename GridPtrContainerT::value_type
470 using GridPtrT =
typename GridPtrContainerT::value_type;
471 typename GridPtrContainerT::const_iterator it =
472 std::find_if(container.begin(), container.end(),
GridNamePred(name));
473 return (it == container.end() ? GridPtrT() : *it);
477 template<
typename KeyT,
typename Gr
idPtrT>
481 using GridPtrMapT = std::map<KeyT, GridPtrT>;
482 for (
typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
485 const GridPtrT& grid = it->second;
486 if (grid && grid->getName() == name)
return grid;
497 template<
typename _TreeType>
528 template<
typename OtherValueType>
560 template<
typename OtherTreeType>
562 #ifdef OPENVDB_3_ABI_COMPATIBLE 576 Grid& operator=(
const Grid&) =
delete;
579 #ifdef OPENVDB_3_ABI_COMPATIBLE 581 Ptr copy(CopyPolicy treePolicy = CP_SHARE)
const;
587 GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE)
const override;
596 Ptr copyWithNewTree()
const;
605 Ptr deepCopy()
const {
return Ptr(
new Grid(*
this)); }
611 Name type()
const override {
return this->gridType(); }
628 bool empty()
const override {
return tree().empty(); }
630 void clear()
override { tree().clear(); }
661 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
667 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
673 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
683 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
692 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
701 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
704 void pruneGrid(
float tolerance = 0.0)
override;
706 #ifndef OPENVDB_2_ABI_COMPATIBLE 707 void clip(
const CoordBBox&)
override;
734 template<
typename OtherTreeType>
749 template<
typename OtherTreeType>
762 template<
typename OtherTreeType>
771 CoordBBox evalActiveVoxelBoundingBox()
const override;
773 Coord evalActiveVoxelDim()
const override;
810 void newTree()
override;
818 void readTopology(std::istream&)
override;
821 void writeTopology(std::ostream&)
const override;
824 void readBuffers(std::istream&)
override;
825 #ifndef OPENVDB_2_ABI_COMPATIBLE 826 void readBuffers(std::istream&,
const CoordBBox&)
override;
833 void readNonresidentBuffers()
const override;
835 void writeBuffers(std::ostream&)
const override;
839 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
844 static inline bool hasMultiPassIO();
876 template<
typename Gr
idType>
877 inline typename GridType::Ptr
880 return GridBase::grid<GridType>(grid);
892 template<
typename Gr
idType>
893 inline typename GridType::ConstPtr
896 return GridBase::constGrid<GridType>(grid);
909 template<
typename Gr
idType>
910 inline typename GridType::Ptr
913 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
914 return gridPtrCast<GridType>(grid->deepCopyGrid());
918 template<
typename Gr
idType>
919 inline typename GridType::Ptr
922 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
932 template<
typename _TreeType>
964 template<
typename _TreeType>
993 template<
typename _TreeType>
1034 template<
typename LeafNodeType>
1036 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1040 template<
typename RootNodeType>
1047 template<
typename TreeType>
1057 template<
typename Gr
idType>
1058 inline typename GridType::Ptr
1063 if (grid && grid->type() == GridType::gridType()) {
1064 return StaticPtrCast<GridType>(grid);
1066 return typename GridType::Ptr();
1070 template<
typename Gr
idType>
1071 inline typename GridType::ConstPtr
1074 return ConstPtrCast<const GridType>(
1075 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1079 template<
typename Gr
idType>
1080 inline typename GridType::ConstPtr
1083 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(grid));
1087 template<
typename Gr
idType>
1088 inline typename GridType::ConstPtr
1091 return ConstPtrCast<const GridType>(
1092 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1099 return ConstPtrCast<TreeBase>(this->constBaseTreePtr());
1114 template<
typename TreeT>
1120 template<
typename TreeT>
1126 template<
typename TreeT>
1133 template<
typename TreeT>
1141 template<
typename TreeT>
1142 template<
typename OtherTreeType>
1150 #ifdef OPENVDB_3_ABI_COMPATIBLE 1151 template<
typename TreeT>
1158 template<
typename TreeT>
1167 template<
typename TreeT>
1176 template<
typename TreeT>
1185 template<
typename TreeT>
1189 return Ptr(
new Grid(background));
1194 template<
typename TreeT>
1203 template<
typename TreeT>
1214 #ifdef OPENVDB_3_ABI_COMPATIBLE 1216 template<
typename TreeT>
1221 switch (treePolicy) {
1227 ret.reset(
new Grid(*
this));
1237 template<
typename TreeT>
1241 return this->
copy(treePolicy);
1244 #else // !OPENVDB_3_ABI_COMPATIBLE 1246 template<
typename TreeT>
1253 template<
typename TreeT>
1261 template<
typename TreeT>
1271 template<
typename TreeT>
1275 return this->
copy();
1278 template<
typename TreeT>
1282 return this->
copy();
1286 template<
typename TreeT>
1293 #endif // OPENVDB_3_ABI_COMPATIBLE 1299 template<
typename TreeT>
1304 if (tree->type() != TreeType::treeType()) {
1306 + tree->type() +
" to a grid of type " + this->
type());
1308 mTree = StaticPtrCast<TreeType>(
tree);
1312 template<
typename TreeT>
1323 template<
typename TreeT>
1327 tree().sparseFill(bbox, value, active);
1331 template<
typename TreeT>
1338 template<
typename TreeT>
1342 tree().denseFill(bbox, value, active);
1345 template<
typename TreeT>
1349 this->
tree().prune(
ValueType(zeroVal<ValueType>() + tolerance));
1352 #ifndef OPENVDB_2_ABI_COMPATIBLE 1353 template<
typename TreeT>
1362 template<
typename TreeT>
1366 tree().merge(other.
tree(), policy);
1370 template<
typename TreeT>
1371 template<
typename OtherTreeType>
1375 tree().topologyUnion(other.
tree());
1379 template<
typename TreeT>
1380 template<
typename OtherTreeType>
1384 tree().topologyIntersection(other.
tree());
1388 template<
typename TreeT>
1389 template<
typename OtherTreeType>
1393 tree().topologyDifference(other.
tree());
1400 template<
typename TreeT>
1404 tree().evalMinMax(minVal, maxVal);
1408 template<
typename TreeT>
1413 tree().evalActiveVoxelBoundingBox(bbox);
1418 template<
typename TreeT>
1423 const bool nonempty =
tree().evalActiveVoxelDim(dim);
1424 return (nonempty ? dim : Coord());
1434 template<
typename TreeT>
1442 template<
typename TreeT>
1450 template<
typename TreeT>
1457 uint16_t numPasses = 1;
1458 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1461 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1462 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1463 meta->setPass(pass);
1470 #ifndef OPENVDB_2_ABI_COMPATIBLE 1474 template<
typename TreeT>
1481 uint16_t numPasses = 1;
1482 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1485 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1486 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1487 meta->setPass(pass);
1497 template<
typename TreeT>
1501 tree().readNonresidentBuffers();
1504 #endif // !OPENVDB_2_ABI_COMPATIBLE 1507 template<
typename TreeT>
1517 uint16_t numPasses = 1;
1518 meta->setCountingPasses(
true);
1521 numPasses =
static_cast<uint16_t
>(meta->pass());
1522 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1523 meta->setCountingPasses(
false);
1526 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1527 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1528 meta->setPass(pass);
1536 template<
typename TreeT>
1544 template<
typename TreeT>
1548 tree().print(os, verboseLevel);
1551 os <<
"Additional metadata:" << std::endl;
1553 os <<
" " << it->first;
1555 const std::string value = it->second->str();
1556 if (!value.empty()) os <<
": " << value;
1562 os <<
"Transform:" << std::endl;
1571 template<
typename Gr
idType>
1572 inline typename GridType::Ptr
1575 return GridType::create(background);
1579 template<
typename Gr
idType>
1580 inline typename GridType::Ptr
1583 return GridType::create();
1587 template<
typename TreePtrType>
1591 using TreeType =
typename TreePtrType::element_type;
1596 template<
typename Gr
idType>
1597 typename GridType::Ptr
1600 using ValueType =
typename GridType::ValueType;
1603 static_assert(std::is_floating_point<ValueType>::value,
1604 "level-set grids must be floating-point-valued");
1606 typename GridType::Ptr
grid = GridType::create(
1607 static_cast<ValueType>(voxelSize * halfWidth));
1616 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:670
~Grid() override
Definition: Grid.h:573
GridNamePred(const Name &_name)
Definition: Grid.h:460
static const TreeType & tree(const GridType &g)
Definition: Grid.h:985
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:479
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:399
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:997
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:628
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:513
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:358
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1035
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:970
UnsafeAccessor getUnsafeAccessor()
Return an accessor that provides random read and write access to this grid's voxels. The accessor is unsafe in the sense that it is not registered by the tree of this grid. In some rare cases this can give a performance advantage over a registered accessor but it is unsafe if the tree topology is modified.
Definition: Grid.h:644
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:1382
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1007
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1005
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:675
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels. The accessor is safe in the sense that it is registered by the tree of this grid.
Definition: Grid.h:635
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:986
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:458
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:444
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:438
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:878
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 writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1509
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1013
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:938
typename GridType::Ptr GridPtrType
Definition: Grid.h:974
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:68
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1589
double Real
Definition: Types.h:63
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:461
typename TreeType::Ptr TreePtrType
Definition: Grid.h:969
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1009
Abstract base class for typed grids.
Definition: Grid.h:103
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:449
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:625
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:1263
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:367
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:954
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:797
Definition: ValueAccessor.h:219
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:363
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:294
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
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:1391
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:161
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:941
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:971
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1420
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:968
static TreeType & tree(GridType &g)
Definition: Grid.h:983
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1402
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1301
typename _TreeType::BuildType BuildType
Definition: Grid.h:508
typename TreeType::Ptr TreePtrType
Definition: Grid.h:998
static const TreeType & constTree(GridType &g)
Definition: Grid.h:957
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:1499
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:945
_TreeType TreeType
Definition: Grid.h:937
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:976
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
Definition: Grid.h:1538
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:346
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:293
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:441
SharedPtr< TreeBase > Ptr
Definition: Tree.h:67
_TreeType TreeType
Definition: Grid.h:996
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:510
static TreeType & tree(TreeType &t)
Definition: Grid.h:982
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:630
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:607
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:796
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:946
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:788
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:505
Definition: version.h:113
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:339
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:361
~GridBase() override
Definition: Grid.h:112
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:1097
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:920
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:1340
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:989
Index64 memUsage() const override
Definition: Grid.h:777
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1364
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:517
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1115
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:451
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1347
GridClass
Definition: Types.h:262
Name name
Definition: Grid.h:462
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:454
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1178
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1452
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:270
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:443
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:348
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:401
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:956
_TreeType TreeType
Definition: Grid.h:967
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1019
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1020
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:500
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:787
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:676
#define OPENVDB_VERSION_NAME
Definition: version.h:43
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:506
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1000
typename _TreeType::ValueType ValueType
Definition: Grid.h:507
Vec3< double > Vec3d
Definition: Vec3.h:708
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1008
static const char *const META_GRID_CREATOR
Definition: Grid.h:291
Definition: Exceptions.h:91
typename TreeType::ValueType ValueType
Definition: Grid.h:977
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:648
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:950
static const TreeType & tree(const GridType &g)
Definition: Grid.h:955
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:518
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:940
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:855
static const TreeType & constTree(GridType &g)
Definition: Grid.h:987
static TreeType & tree(TreeType &t)
Definition: Grid.h:952
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...
Definition: Exceptions.h:39
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:984
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1014
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:442
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1015
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:1436
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:347
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:515
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:769
_TreeType TreeType
Definition: Grid.h:504
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:453
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:1598
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:1444
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:296
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:447
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:980
typename TreeType::ValueType ValueType
Definition: Grid.h:1006
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:299
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:409
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:949
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:297
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:1325
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:1373
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:298
static TreeType & tree(GridType &g)
Definition: Grid.h:953
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:1059
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1017
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:664
Definition: Exceptions.h:92
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:798
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:186
uint64_t Index64
Definition: Types.h:56
MergePolicy
Definition: Types.h:315
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:519
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:979
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:613
std::string Name
Definition: Name.h:44
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:412
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:663
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:446
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:185
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1314
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:959
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1355
typename GridType::Ptr GridPtrType
Definition: Grid.h:1003
tree::TreeBase TreeBase
Definition: Grid.h:52
static TreeType & tree(TreeType &t)
Definition: Grid.h:1011
std::shared_ptr< T > SharedPtr
Definition: Types.h:130
typename TreeType::ValueType ValueType
Definition: Grid.h:947
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
VecType
Definition: Types.h:292
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:948
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1104
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:338
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:620
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:935
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1410
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:436
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:502
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:975
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:514
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:1333
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:958
GridBase::Ptr copyGrid() override
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition: Grid.h:1273
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:300
SharedPtr< GridBase > Ptr
Definition: Grid.h:106
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:511
static const char *const META_GRID_CLASS
Definition: Grid.h:290
typename GridType::Ptr GridPtrType
Definition: Grid.h:944
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:1255
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:437
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:611
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:851
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:156
Base class for typed trees.
Definition: Tree.h:64
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:512
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:452
static const char *const META_GRID_NAME
Definition: Grid.h:292
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:175
static TreeType & tree(GridType &g)
Definition: Grid.h:1012
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:978
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:853
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1016
SharedPtr< Grid > Ptr
Definition: Grid.h:501
static const char *const META_VECTOR_TYPE
Definition: Grid.h:295
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:448
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:999
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:669
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:894
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:520
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:107
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:439
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1546
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:529
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:1081
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1018
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:789
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1004
typename TreeType::Ptr TreePtrType
Definition: Grid.h:939
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:988
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:1288