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>
115 #if OPENVDB_ABI_VERSION_NUMBER <= 3 116 virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE)
const = 0;
141 static bool isRegistered(
const Name &type);
144 static void clearRegistry();
151 virtual Name type()
const = 0;
153 virtual Name valueType()
const = 0;
156 template<
typename Gr
idType>
157 bool isType()
const {
return (this->type() == GridType::gridType()); }
160 template<
typename Gr
idType>
164 template<
typename Gr
idType>
166 template<
typename Gr
idType>
167 static typename GridType::ConstPtr constGrid(
const GridBase::Ptr&);
168 template<
typename Gr
idType>
181 TreeBase& baseTree() {
return const_cast<TreeBase&
>(this->constBaseTree()); }
198 virtual void newTree() = 0;
201 virtual bool empty()
const = 0;
203 virtual void clear() = 0;
210 virtual void pruneGrid(
float tolerance = 0.0) = 0;
212 #if OPENVDB_ABI_VERSION_NUMBER >= 3 213 void clipGrid(
const BBoxd&);
231 std::string getName()
const;
233 void setName(
const std::string&);
236 std::string getCreator()
const;
238 void setCreator(
const std::string&);
242 bool saveFloatAsHalf()
const;
243 void setSaveFloatAsHalf(
bool);
250 void clearGridClass();
253 static std::string gridClassToString(
GridClass);
255 static std::string gridClassToMenuName(
GridClass);
259 static GridClass stringToGridClass(
const std::string&);
268 void clearVectorType();
271 static std::string vecTypeToString(
VecType);
274 static std::string vecTypeExamples(
VecType);
277 static std::string vecTypeDescription(
VecType);
278 static VecType stringToVecType(
const std::string&);
283 bool isInWorldSpace()
const;
285 void setIsInWorldSpace(
bool);
308 virtual Index64 activeVoxelCount()
const = 0;
312 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
315 virtual Coord evalActiveVoxelDim()
const = 0;
318 virtual Index64 memUsage()
const = 0;
324 void addStatsMetadata();
366 Vec3d indexToWorld(
const Vec3d& xyz)
const {
return transform().indexToWorld(xyz); }
370 Vec3d worldToIndex(
const Vec3d& xyz)
const {
return transform().worldToIndex(xyz); }
379 virtual void readTopology(std::istream&) = 0;
382 virtual void writeTopology(std::ostream&)
const = 0;
385 virtual void readBuffers(std::istream&) = 0;
386 #if OPENVDB_ABI_VERSION_NUMBER >= 3 387 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
394 virtual void readNonresidentBuffers()
const = 0;
396 virtual void writeBuffers(std::ostream&)
const = 0;
405 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
410 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
415 #if OPENVDB_ABI_VERSION_NUMBER <= 3 426 static void unregisterGrid(
const Name& type);
467 template<
typename Gr
idPtrContainerT>
468 inline typename GridPtrContainerT::value_type
471 using GridPtrT =
typename GridPtrContainerT::value_type;
472 typename GridPtrContainerT::const_iterator it =
473 std::find_if(container.begin(), container.end(),
GridNamePred(name));
474 return (it == container.end() ? GridPtrT() : *it);
478 template<
typename KeyT,
typename Gr
idPtrT>
482 using GridPtrMapT = std::map<KeyT, GridPtrT>;
483 for (
typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
486 const GridPtrT& grid = it->second;
487 if (grid && grid->getName() == name)
return grid;
498 template<
typename _TreeType>
529 template<
typename OtherValueType>
561 template<
typename OtherTreeType>
563 #if OPENVDB_ABI_VERSION_NUMBER <= 3 577 Grid& operator=(
const Grid&) =
delete;
580 #if OPENVDB_ABI_VERSION_NUMBER <= 3 582 Ptr copy(CopyPolicy treePolicy = CP_SHARE)
const;
589 GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE)
const override;
598 Ptr copyWithNewTree()
const;
607 Ptr deepCopy()
const {
return Ptr(
new Grid(*
this)); }
613 Name type()
const override {
return this->gridType(); }
630 bool empty()
const override {
return tree().empty(); }
632 void clear()
override { tree().clear(); }
663 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
669 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
675 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
706 void pruneGrid(
float tolerance = 0.0)
override;
708 #if OPENVDB_ABI_VERSION_NUMBER >= 3 736 template<
typename OtherTreeType>
751 template<
typename OtherTreeType>
764 template<
typename OtherTreeType>
773 CoordBBox evalActiveVoxelBoundingBox()
const override;
775 Coord evalActiveVoxelDim()
const override;
812 void newTree()
override;
820 void readTopology(std::istream&)
override;
823 void writeTopology(std::ostream&)
const override;
826 void readBuffers(std::istream&)
override;
827 #if OPENVDB_ABI_VERSION_NUMBER >= 3 828 void readBuffers(std::istream&,
const CoordBBox&)
override;
835 void readNonresidentBuffers()
const override;
837 void writeBuffers(std::ostream&)
const override;
841 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
846 static inline bool hasMultiPassIO();
860 <<
" might not be threadsafe on this platform");
885 template<
typename Gr
idType>
886 inline typename GridType::Ptr
889 return GridBase::grid<GridType>(grid);
901 template<
typename Gr
idType>
902 inline typename GridType::ConstPtr
905 return GridBase::constGrid<GridType>(grid);
918 template<
typename Gr
idType>
919 inline typename GridType::Ptr
922 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
923 return gridPtrCast<GridType>(grid->deepCopyGrid());
927 template<
typename Gr
idType>
928 inline typename GridType::Ptr
931 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
941 template<
typename _TreeType>
973 template<
typename _TreeType>
1002 template<
typename _TreeType>
1043 template<
typename LeafNodeType>
1045 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1049 template<
typename RootNodeType>
1056 template<
typename TreeType>
1066 template<
typename Gr
idType>
1067 inline typename GridType::Ptr
1072 if (grid && grid->type() == GridType::gridType()) {
1073 return StaticPtrCast<GridType>(grid);
1075 return typename GridType::Ptr();
1079 template<
typename Gr
idType>
1080 inline typename GridType::ConstPtr
1083 return ConstPtrCast<const GridType>(
1084 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1088 template<
typename Gr
idType>
1089 inline typename GridType::ConstPtr
1092 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(grid));
1096 template<
typename Gr
idType>
1097 inline typename GridType::ConstPtr
1100 return ConstPtrCast<const GridType>(
1101 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1108 return ConstPtrCast<TreeBase>(this->constBaseTreePtr());
1123 template<
typename TreeT>
1129 template<
typename TreeT>
1135 template<
typename TreeT>
1142 template<
typename TreeT>
1150 template<
typename TreeT>
1151 template<
typename OtherTreeType>
1159 #if OPENVDB_ABI_VERSION_NUMBER <= 3 1160 template<
typename TreeT>
1167 template<
typename TreeT>
1176 template<
typename TreeT>
1185 template<
typename TreeT>
1194 template<
typename TreeT>
1198 return Ptr(
new Grid(background));
1203 template<
typename TreeT>
1212 template<
typename TreeT>
1223 #if OPENVDB_ABI_VERSION_NUMBER <= 3 1225 template<
typename TreeT>
1230 switch (treePolicy) {
1236 ret.reset(
new Grid(*
this));
1246 template<
typename TreeT>
1250 return this->
copy(treePolicy);
1253 #else // if OPENVDB_ABI_VERSION_NUMBER > 3 1255 template<
typename TreeT>
1262 template<
typename TreeT>
1270 template<
typename TreeT>
1280 template<
typename TreeT>
1284 return this->
copy();
1287 template<
typename TreeT>
1291 return this->
copy();
1295 template<
typename TreeT>
1308 template<
typename TreeT>
1313 if (tree->type() != TreeType::treeType()) {
1315 + tree->type() +
" to a grid of type " + this->
type());
1317 mTree = StaticPtrCast<TreeType>(
tree);
1321 template<
typename TreeT>
1332 template<
typename TreeT>
1336 tree().sparseFill(bbox, value, active);
1340 template<
typename TreeT>
1347 template<
typename TreeT>
1351 tree().denseFill(bbox, value, active);
1354 template<
typename TreeT>
1358 this->
tree().prune(
ValueType(zeroVal<ValueType>() + tolerance));
1361 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1362 template<
typename TreeT>
1371 template<
typename TreeT>
1375 tree().merge(other.
tree(), policy);
1379 template<
typename TreeT>
1380 template<
typename OtherTreeType>
1384 tree().topologyUnion(other.
tree());
1388 template<
typename TreeT>
1389 template<
typename OtherTreeType>
1393 tree().topologyIntersection(other.
tree());
1397 template<
typename TreeT>
1398 template<
typename OtherTreeType>
1402 tree().topologyDifference(other.
tree());
1409 template<
typename TreeT>
1413 tree().evalMinMax(minVal, maxVal);
1417 template<
typename TreeT>
1422 tree().evalActiveVoxelBoundingBox(bbox);
1427 template<
typename TreeT>
1432 const bool nonempty =
tree().evalActiveVoxelDim(dim);
1433 return (nonempty ? dim :
Coord());
1443 template<
typename TreeT>
1451 template<
typename TreeT>
1459 template<
typename TreeT>
1466 uint16_t numPasses = 1;
1467 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1470 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1471 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1472 meta->setPass(pass);
1479 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1483 template<
typename TreeT>
1490 uint16_t numPasses = 1;
1491 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1494 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1495 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1496 meta->setPass(pass);
1506 template<
typename TreeT>
1510 tree().readNonresidentBuffers();
1516 template<
typename TreeT>
1526 uint16_t numPasses = 1;
1527 meta->setCountingPasses(
true);
1530 numPasses =
static_cast<uint16_t
>(meta->pass());
1531 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1532 meta->setCountingPasses(
false);
1535 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1536 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1537 meta->setPass(pass);
1545 template<
typename TreeT>
1553 template<
typename TreeT>
1557 tree().print(os, verboseLevel);
1560 os <<
"Additional metadata:" << std::endl;
1562 os <<
" " << it->first;
1564 const std::string value = it->second->str();
1565 if (!value.empty()) os <<
": " << value;
1571 os <<
"Transform:" << std::endl;
1580 template<
typename Gr
idType>
1581 inline typename GridType::Ptr
1584 return GridType::create(background);
1588 template<
typename Gr
idType>
1589 inline typename GridType::Ptr
1592 return GridType::create();
1596 template<
typename TreePtrType>
1600 using TreeType =
typename TreePtrType::element_type;
1605 template<
typename Gr
idType>
1606 typename GridType::Ptr
1609 using ValueType =
typename GridType::ValueType;
1612 static_assert(std::is_floating_point<ValueType>::value,
1613 "level-set grids must be floating-point-valued");
1615 typename GridType::Ptr
grid = GridType::create(
1616 static_cast<ValueType>(voxelSize * halfWidth));
1625 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:66
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:771
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
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:903
static const TreeType & constTree(GridType &g)
Definition: Grid.h:996
typename GridType::Ptr GridPtrType
Definition: Grid.h:983
static const char *const META_GRID_CLASS
Definition: Grid.h:291
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1310
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:264
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1022
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:987
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:453
static const TreeType & constTree(GridType &g)
Definition: Grid.h:966
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:299
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:993
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:447
double Real
Definition: Types.h:67
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1323
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:452
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...
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:176
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:157
static TreeType & tree(TreeType &t)
Definition: Grid.h:961
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:530
static const char *const META_VECTOR_TYPE
Definition: Grid.h:296
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:1297
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:965
typename GridType::Ptr GridPtrType
Definition: Grid.h:1012
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:632
static TreeType & tree(GridType &g)
Definition: Grid.h:962
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:671
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:368
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1373
typename _TreeType::ValueType ValueType
Definition: Grid.h:508
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:677
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:400
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
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:1068
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:954
tree::TreeBase TreeBase
Definition: Grid.h:53
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:507
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:957
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:1445
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:985
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:678
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:997
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:989
std::string Name
Definition: Name.h:44
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:1508
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1014
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
Definition: Exceptions.h:91
GridNamePred(const Name &_name)
Definition: Grid.h:461
Name name
Definition: Grid.h:463
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1113
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1044
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
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:791
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1018
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:503
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:790
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:929
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:988
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:439
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:518
static const TreeType & tree(const GridType &g)
Definition: Grid.h:964
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1024
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:637
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:1090
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:800
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:364
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1008
typename TreeType::ValueType ValueType
Definition: Grid.h:956
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:519
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1411
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:609
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:348
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:521
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
Base class for typed trees.
Definition: Tree.h:62
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
Definition: Grid.h:1547
Definition: LeafBuffer.h:67
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1555
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:650
Ptr(*)() GridFactory
Definition: Grid.h:110
Definition: ValueAccessor.h:220
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:283
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:947
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1029
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:440
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:627
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:853
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:462
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:459
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:958
typename _TreeType::BuildType BuildType
Definition: Grid.h:509
typename TreeType::ValueType ValueType
Definition: Grid.h:1015
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1461
static const char *const META_GRID_CREATOR
Definition: Grid.h:292
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:646
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:1349
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:108
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:855
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:613
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:615
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:512
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:516
Vec3< double > Vec3d
Definition: Vec3.h:679
typename TreeType::Ptr TreePtrType
Definition: Grid.h:948
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1017
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:980
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:998
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:438
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:622
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:979
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1006
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:963
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1027
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1013
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:449
Definition: Exceptions.h:92
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1025
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:506
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:280
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:515
typename TreeType::ValueType ValueType
Definition: Grid.h:986
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:480
static const TreeType & tree(const GridType &g)
Definition: Grid.h:994
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1518
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:666
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:450
SharedPtr< Grid > Ptr
Definition: Grid.h:502
GridClass
Definition: Types.h:275
static TreeType & tree(TreeType &t)
Definition: Grid.h:1020
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:444
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:300
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:995
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1419
Definition: Exceptions.h:40
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:1382
_TreeType TreeType
Definition: Grid.h:1005
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:298
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:1607
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:294
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:968
Index64 memUsage() const override
Definition: Grid.h:779
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:977
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:448
VecType
Definition: Types.h:305
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1187
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:955
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:410
Abstract base class for typed grids.
Definition: Grid.h:104
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1429
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:864
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:402
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:887
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1124
static TreeType & tree(GridType &g)
Definition: Grid.h:992
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:665
uint64_t Index64
Definition: Types.h:60
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:443
MergePolicy
Definition: Types.h:328
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:984
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
static const char *const META_GRID_NAME
Definition: Grid.h:293
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:513
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:950
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1007
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:949
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
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:339
Definition: version.h:232
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1364
~GridBase() override
Definition: Grid.h:113
_TreeType TreeType
Definition: Grid.h:976
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:297
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:1106
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:349
OPENVDB_API void setGridClass(std::ios_base &, uint32_t)
Associate with the given stream the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently ...
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
SharedPtr< TreeBase > Ptr
Definition: Tree.h:65
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:437
static TreeType & tree(TreeType &t)
Definition: Grid.h:991
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:959
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:1453
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:359
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1016
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:1272
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:340
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1023
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:445
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:455
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:1282
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:789
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:295
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1598
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:454
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1028
_TreeType TreeType
Definition: Grid.h:946
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:442
typename TreeType::Ptr TreePtrType
Definition: Grid.h:978
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:413
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
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:1391
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1356
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:967
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:187
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
static TreeType & tree(GridType &g)
Definition: Grid.h:1021
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:672
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:515
_TreeType TreeType
Definition: Grid.h:505
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:1334
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:798
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:186
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:301
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:347
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:1264
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:944
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:799
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:514
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:362
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:630
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:1342
~Grid() override
Definition: Grid.h:574
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1026
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:1400
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1009
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:520
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:511
typename GridType::Ptr GridPtrType
Definition: Grid.h:953