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 424 static void registerGrid(
const Name& type, GridFactory);
426 static void unregisterGrid(
const Name& type);
430 math::Transform::Ptr mTransform;
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;
596 ConstPtr copy()
const;
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(); }
648 ConstAccessor getAccessor()
const {
return ConstAccessor(tree()); }
652 ConstUnsafeAccessor getConstUnsafeAccessor()
const {
return ConstUnsafeAccessor(tree()); }
663 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
669 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
675 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
682 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
685 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
694 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
703 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
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;
786 TreePtrType treePtr() {
return mTree; }
794 TreeType& tree() {
return *mTree; }
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>
1154 mTree(new
TreeType(other.constTree()))
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>
1299 return this->copyWithNewTree();
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>
1325 mTree.reset(
new TreeType(this->background()));
1332 template<
typename TreeT>
1336 tree().sparseFill(bbox, value, active);
1340 template<
typename TreeT>
1344 this->sparseFill(bbox, value, active);
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>
1447 tree().readTopology(is, saveFloatAsHalf());
1451 template<
typename TreeT>
1455 tree().writeTopology(os, saveFloatAsHalf());
1459 template<
typename TreeT>
1464 tree().readBuffers(is, saveFloatAsHalf());
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);
1473 tree().readBuffers(is, saveFloatAsHalf());
1479 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1483 template<
typename TreeT>
1488 tree().readBuffers(is, bbox, saveFloatAsHalf());
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);
1497 tree().readBuffers(is, saveFloatAsHalf());
1506 template<
typename TreeT>
1510 tree().readNonresidentBuffers();
1516 template<
typename TreeT>
1520 if (!hasMultiPassIO()) {
1521 tree().writeBuffers(os, saveFloatAsHalf());
1526 uint16_t numPasses = 1;
1527 meta->setCountingPasses(
true);
1529 tree().writeBuffers(os, saveFloatAsHalf());
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);
1538 tree().writeBuffers(os, saveFloatAsHalf());
1545 template<
typename TreeT>
1553 template<
typename TreeT>
1557 tree().print(os, verboseLevel);
1559 if (metaCount() > 0) {
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;
1572 transform().print(os,
" ");
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 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
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:442
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
_TreeType TreeType
Definition: Grid.h:976
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:455
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
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:448
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:864
static TreeType & tree(TreeType &t)
Definition: Grid.h:961
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
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:297
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:947
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:853
static TreeType & tree(TreeType &t)
Definition: Grid.h:991
Abstract base class for typed grids.
Definition: Grid.h:104
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:157
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1018
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:444
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:295
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:459
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1364
uint64_t Index64
Definition: Types.h:60
SharedPtr< Grid > Ptr
Definition: Grid.h:502
UnsafeAccessor getUnsafeAccessor()
Return an accessor that provides random read and write access to this grid's voxels....
Definition: Grid.h:646
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
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1582
static const TreeType & constTree(GridType &g)
Definition: Grid.h:996
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:368
static const char *const META_GRID_CREATOR
Definition: Grid.h:292
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:299
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:400
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:666
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:622
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:987
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
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:187
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
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:979
GridNamePred(const Name &_name)
Definition: Grid.h:461
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:613
VecType
Definition: Types.h:305
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1429
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:449
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:967
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:512
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:955
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
static const TreeType & tree(const GridType &g)
Definition: Grid.h:994
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
Vec3< double > Vec3d
Definition: Vec3.h:679
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1419
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1044
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1124
typename TreeType::ValueType ValueType
Definition: Grid.h:1015
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1022
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:362
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:665
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:462
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:453
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1023
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
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 TreeType & constTree(TreeType &t)
Definition: Grid.h:995
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
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1518
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
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1006
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:977
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1356
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:301
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:364
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
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
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
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
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1016
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
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
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:515
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:520
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
tree::TreeBase TreeBase
Definition: Grid.h:53
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1187
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:959
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:993
Definition: Exceptions.h:91
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
static TreeType & tree(GridType &g)
Definition: Grid.h:992
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...
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:454
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:438
static TreeType & tree(TreeType &t)
Definition: Grid.h:1020
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1027
typename TreeType::Ptr TreePtrType
Definition: Grid.h:978
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
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:511
GridClass
Definition: Types.h:275
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1013
Name name
Definition: Grid.h:463
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:283
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:339
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:954
Definition: LeafBuffer.h:67
SharedPtr< TreeBase > Ptr
Definition: Tree.h:65
static TreeType & tree(GridType &g)
Definition: Grid.h:962
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:66
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
_TreeType TreeType
Definition: Grid.h:505
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 ...
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:798
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1310
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1007
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:949
_TreeType TreeType
Definition: Grid.h:1005
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:280
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:515
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1323
typename TreeType::ValueType ValueType
Definition: Grid.h:956
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:630
static const TreeType & tree(const GridType &g)
Definition: Grid.h:964
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels....
Definition: Grid.h:637
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:963
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:672
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:186
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:503
Definition: Exceptions.h:40
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:264
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 _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:507
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:298
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:632
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1025
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:771
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform.
Definition: Grid.h:1113
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:445
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:410
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
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:349
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1017
Ptr(*)() GridFactory
Definition: Grid.h:110
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:1391
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:518
_TreeType TreeType
Definition: Grid.h:946
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:530
typename _TreeType::ValueType ValueType
Definition: Grid.h:508
typename GridType::Ptr GridPtrType
Definition: Grid.h:1012
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:402
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1028
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1555
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
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:965
static const char *const META_GRID_CLASS
Definition: Grid.h:291
Definition: ValueAccessor.h:220
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:677
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:1400
Base class for typed trees.
Definition: Tree.h:62
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1026
typename TreeType::Ptr TreePtrType
Definition: Grid.h:948
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:519
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:294
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:439
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:997
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:957
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:671
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1411
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
static const char *const META_VECTOR_TYPE
Definition: Grid.h:296
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:452
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 NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:980
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
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:359
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:968
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:678
static const char *const META_GRID_NAME
Definition: Grid.h:293
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:443
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
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
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:998
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:108
typename GridType::Ptr GridPtrType
Definition: Grid.h:953
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:984
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1009
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:340
~GridBase() override
Definition: Grid.h:113
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
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1024
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
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:300
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1029
typename _TreeType::BuildType BuildType
Definition: Grid.h:509
static const TreeType & constTree(GridType &g)
Definition: Grid.h:966
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:615
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1008
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:437
Definition: Exceptions.h:92
typename TreeType::ValueType ValueType
Definition: Grid.h:986
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:800
MergePolicy
Definition: Types.h:328
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:521
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:450
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:506
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:985
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:958
Index64 memUsage() const override
Definition: Grid.h:779
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1461
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:855
Definition: version.h:232
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
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:950
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:440
std::string Name
Definition: Name.h:44
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:627
typename GridType::Ptr GridPtrType
Definition: Grid.h:983
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:989
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:988
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1014
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:447
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
double Real
Definition: Types.h:67
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:413
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:650
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
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:513
static TreeType & tree(GridType &g)
Definition: Grid.h:1021
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:516