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 #ifdef OPENVDB_3_ABI_COMPATIBLE 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 #ifndef OPENVDB_2_ABI_COMPATIBLE 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 #ifndef OPENVDB_2_ABI_COMPATIBLE 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 #ifdef OPENVDB_3_ABI_COMPATIBLE 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 #ifdef OPENVDB_3_ABI_COMPATIBLE 577 Grid& operator=(
const Grid&) =
delete;
580 #ifdef OPENVDB_3_ABI_COMPATIBLE 582 Ptr copy(CopyPolicy treePolicy = CP_SHARE)
const;
588 GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE)
const override;
597 Ptr copyWithNewTree()
const;
606 Ptr deepCopy()
const {
return Ptr(
new Grid(*
this)); }
612 Name type()
const override {
return this->gridType(); }
629 bool empty()
const override {
return tree().empty(); }
631 void clear()
override { tree().clear(); }
662 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
668 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
674 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
705 void pruneGrid(
float tolerance = 0.0)
override;
707 #ifndef OPENVDB_2_ABI_COMPATIBLE 735 template<
typename OtherTreeType>
750 template<
typename OtherTreeType>
763 template<
typename OtherTreeType>
772 CoordBBox evalActiveVoxelBoundingBox()
const override;
774 Coord evalActiveVoxelDim()
const override;
811 void newTree()
override;
819 void readTopology(std::istream&)
override;
822 void writeTopology(std::ostream&)
const override;
825 void readBuffers(std::istream&)
override;
826 #ifndef OPENVDB_2_ABI_COMPATIBLE 827 void readBuffers(std::istream&,
const CoordBBox&)
override;
834 void readNonresidentBuffers()
const override;
836 void writeBuffers(std::ostream&)
const override;
840 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
845 static inline bool hasMultiPassIO();
859 <<
" might not be threadsafe on this platform");
884 template<
typename Gr
idType>
885 inline typename GridType::Ptr
888 return GridBase::grid<GridType>(grid);
900 template<
typename Gr
idType>
901 inline typename GridType::ConstPtr
904 return GridBase::constGrid<GridType>(grid);
917 template<
typename Gr
idType>
918 inline typename GridType::Ptr
921 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
922 return gridPtrCast<GridType>(grid->deepCopyGrid());
926 template<
typename Gr
idType>
927 inline typename GridType::Ptr
930 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
940 template<
typename _TreeType>
972 template<
typename _TreeType>
1001 template<
typename _TreeType>
1042 template<
typename LeafNodeType>
1044 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1048 template<
typename RootNodeType>
1055 template<
typename TreeType>
1065 template<
typename Gr
idType>
1066 inline typename GridType::Ptr
1071 if (grid && grid->type() == GridType::gridType()) {
1072 return StaticPtrCast<GridType>(grid);
1074 return typename GridType::Ptr();
1078 template<
typename Gr
idType>
1079 inline typename GridType::ConstPtr
1082 return ConstPtrCast<const GridType>(
1083 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1087 template<
typename Gr
idType>
1088 inline typename GridType::ConstPtr
1091 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(grid));
1095 template<
typename Gr
idType>
1096 inline typename GridType::ConstPtr
1099 return ConstPtrCast<const GridType>(
1100 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1107 return ConstPtrCast<TreeBase>(this->constBaseTreePtr());
1122 template<
typename TreeT>
1128 template<
typename TreeT>
1134 template<
typename TreeT>
1141 template<
typename TreeT>
1149 template<
typename TreeT>
1150 template<
typename OtherTreeType>
1158 #ifdef OPENVDB_3_ABI_COMPATIBLE 1159 template<
typename TreeT>
1166 template<
typename TreeT>
1175 template<
typename TreeT>
1184 template<
typename TreeT>
1193 template<
typename TreeT>
1197 return Ptr(
new Grid(background));
1202 template<
typename TreeT>
1211 template<
typename TreeT>
1222 #ifdef OPENVDB_3_ABI_COMPATIBLE 1224 template<
typename TreeT>
1229 switch (treePolicy) {
1235 ret.reset(
new Grid(*
this));
1245 template<
typename TreeT>
1249 return this->
copy(treePolicy);
1252 #else // !OPENVDB_3_ABI_COMPATIBLE 1254 template<
typename TreeT>
1261 template<
typename TreeT>
1269 template<
typename TreeT>
1279 template<
typename TreeT>
1283 return this->
copy();
1286 template<
typename TreeT>
1290 return this->
copy();
1294 template<
typename TreeT>
1301 #endif // OPENVDB_3_ABI_COMPATIBLE 1307 template<
typename TreeT>
1312 if (tree->type() != TreeType::treeType()) {
1314 + tree->type() +
" to a grid of type " + this->
type());
1316 mTree = StaticPtrCast<TreeType>(
tree);
1320 template<
typename TreeT>
1331 template<
typename TreeT>
1335 tree().sparseFill(bbox, value, active);
1339 template<
typename TreeT>
1346 template<
typename TreeT>
1350 tree().denseFill(bbox, value, active);
1353 template<
typename TreeT>
1357 this->
tree().prune(
ValueType(zeroVal<ValueType>() + tolerance));
1360 #ifndef OPENVDB_2_ABI_COMPATIBLE 1361 template<
typename TreeT>
1370 template<
typename TreeT>
1374 tree().merge(other.
tree(), policy);
1378 template<
typename TreeT>
1379 template<
typename OtherTreeType>
1383 tree().topologyUnion(other.
tree());
1387 template<
typename TreeT>
1388 template<
typename OtherTreeType>
1392 tree().topologyIntersection(other.
tree());
1396 template<
typename TreeT>
1397 template<
typename OtherTreeType>
1401 tree().topologyDifference(other.
tree());
1408 template<
typename TreeT>
1412 tree().evalMinMax(minVal, maxVal);
1416 template<
typename TreeT>
1421 tree().evalActiveVoxelBoundingBox(bbox);
1426 template<
typename TreeT>
1431 const bool nonempty =
tree().evalActiveVoxelDim(dim);
1432 return (nonempty ? dim :
Coord());
1442 template<
typename TreeT>
1450 template<
typename TreeT>
1458 template<
typename TreeT>
1465 uint16_t numPasses = 1;
1466 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1469 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1470 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1471 meta->setPass(pass);
1478 #ifndef OPENVDB_2_ABI_COMPATIBLE 1482 template<
typename TreeT>
1489 uint16_t numPasses = 1;
1490 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1493 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1494 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1495 meta->setPass(pass);
1505 template<
typename TreeT>
1509 tree().readNonresidentBuffers();
1512 #endif // !OPENVDB_2_ABI_COMPATIBLE 1515 template<
typename TreeT>
1525 uint16_t numPasses = 1;
1526 meta->setCountingPasses(
true);
1529 numPasses =
static_cast<uint16_t
>(meta->pass());
1530 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1531 meta->setCountingPasses(
false);
1534 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1535 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1536 meta->setPass(pass);
1544 template<
typename TreeT>
1552 template<
typename TreeT>
1556 tree().print(os, verboseLevel);
1559 os <<
"Additional metadata:" << std::endl;
1561 os <<
" " << it->first;
1563 const std::string value = it->second->str();
1564 if (!value.empty()) os <<
": " << value;
1570 os <<
"Transform:" << std::endl;
1579 template<
typename Gr
idType>
1580 inline typename GridType::Ptr
1583 return GridType::create(background);
1587 template<
typename Gr
idType>
1588 inline typename GridType::Ptr
1591 return GridType::create();
1595 template<
typename TreePtrType>
1599 using TreeType =
typename TreePtrType::element_type;
1604 template<
typename Gr
idType>
1605 typename GridType::Ptr
1608 using ValueType =
typename GridType::ValueType;
1611 static_assert(std::is_floating_point<ValueType>::value,
1612 "level-set grids must be floating-point-valued");
1614 typename GridType::Ptr
grid = GridType::create(
1615 static_cast<ValueType>(voxelSize * halfWidth));
1624 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:299
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:996
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:108
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:612
GridNamePred(const Name &_name)
Definition: Grid.h:461
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1028
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:68
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:1452
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:954
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:515
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:1341
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:956
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
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:1281
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:511
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:631
static TreeType & tree(GridType &g)
Definition: Grid.h:991
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:444
std::shared_ptr< T > SharedPtr
Definition: Types.h:130
double Real
Definition: Types.h:63
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:512
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:797
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1025
static const TreeType & constTree(GridType &g)
Definition: Grid.h:965
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:440
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:671
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:506
_TreeType TreeType
Definition: Grid.h:945
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:1263
typename TreeType::Ptr TreePtrType
Definition: Grid.h:977
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:967
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:852
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:962
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:513
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:297
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1372
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:300
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1123
Ptr(*)() GridFactory
Definition: Grid.h:110
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1355
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:949
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:854
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:964
SharedPtr< Grid > Ptr
Definition: Grid.h:502
static TreeType & tree(TreeType &t)
Definition: Grid.h:990
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:521
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1460
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1517
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1428
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:294
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:437
typename TreeType::ValueType ValueType
Definition: Grid.h:1014
~Grid() override
Definition: Grid.h:574
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:413
Index64 memUsage() const override
Definition: Grid.h:778
typename _TreeType::ValueType ValueType
Definition: Grid.h:508
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1597
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:261
static const char *const META_GRID_CREATOR
Definition: Grid.h:292
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:984
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:514
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:339
static constexpr bool IsAtomic
true if LeafBuffer::mOutOfCore is atomic, false otherwise
Definition: LeafBuffer.h:76
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1418
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:645
~GridBase() override
Definition: Grid.h:113
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:519
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:1105
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:1606
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:459
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:799
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:790
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:976
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:994
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:863
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:665
typename TreeType::ValueType ValueType
Definition: Grid.h:985
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:447
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:664
static TreeType & tree(GridType &g)
Definition: Grid.h:1020
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:979
typename GridType::Ptr GridPtrType
Definition: Grid.h:1011
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:997
static TreeType & tree(TreeType &t)
Definition: Grid.h:1019
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1007
static const TreeType & tree(const GridType &g)
Definition: Grid.h:963
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:516
Name name
Definition: Grid.h:463
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:402
_TreeType TreeType
Definition: Grid.h:505
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1012
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:677
uint64_t Index64
Definition: Types.h:56
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:1399
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:340
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:948
_TreeType TreeType
Definition: Grid.h:975
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:500
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:359
std::string Name
Definition: Name.h:44
static const TreeType & constTree(GridType &g)
Definition: Grid.h:995
typename _TreeType::BuildType BuildType
Definition: Grid.h:509
static const char *const META_GRID_NAME
Definition: Grid.h:293
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1554
#define OPENVDB_VERSION_NAME
Definition: version.h:43
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:608
tree::TreeBase TreeBase
Definition: Grid.h:53
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
Definition: Grid.h:1546
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1013
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:1089
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:953
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:279
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
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:649
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:448
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1021
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:626
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:614
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:400
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1017
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1024
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:992
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:957
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:629
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:1348
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:362
Definition: Exceptions.h:39
VecType
Definition: Types.h:292
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:518
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:770
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:438
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1026
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:966
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:983
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:445
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:442
Vec3< double > Vec3d
Definition: Vec3.h:678
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:1296
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1186
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:928
Definition: ValueAccessor.h:219
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:503
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
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:988
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:157
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1005
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:449
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1015
static TreeType & tree(GridType &g)
Definition: Grid.h:961
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:507
Definition: version.h:113
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:453
Definition: Exceptions.h:92
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:452
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:986
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1043
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:270
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:455
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:450
static const char *const META_VECTOR_TYPE
Definition: Grid.h:296
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:186
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:1067
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:349
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:368
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:670
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:987
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:454
MergePolicy
Definition: Types.h:315
typename GridType::Ptr GridPtrType
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...
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:1507
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:439
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1410
Abstract base class for typed grids.
Definition: Grid.h:104
GridClass
Definition: Types.h:262
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:676
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:48
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:978
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1006
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:1444
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:443
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
static const char *const META_GRID_CLASS
Definition: Grid.h:291
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 ...
Definition: Exceptions.h:91
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1027
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1112
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:1390
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:364
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:958
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:636
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:295
static const TreeType & tree(const GridType &g)
Definition: Grid.h:993
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1008
_TreeType TreeType
Definition: Grid.h:1004
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:798
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1016
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:788
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:187
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:348
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:1333
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:1381
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:943
static TreeType & tree(TreeType &t)
Definition: Grid.h:960
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:886
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:301
typename TreeType::ValueType ValueType
Definition: Grid.h:955
Base class for typed trees.
Definition: Tree.h:64
SharedPtr< TreeBase > Ptr
Definition: Tree.h:67
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:347
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:789
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:520
typename GridType::Ptr GridPtrType
Definition: Grid.h:982
typename TreeType::Ptr TreePtrType
Definition: Grid.h:947
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1322
typename std::remove_const< TreeType >::type NonConstTreeType
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
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1363
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1022
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:1271
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:410
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1309
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1023
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:298
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:902
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:621
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:462