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;
588 GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE)
const override;
595 ConstPtr copy()
const;
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(); }
647 ConstAccessor getAccessor()
const {
return ConstAccessor(tree()); }
651 ConstUnsafeAccessor getConstUnsafeAccessor()
const {
return ConstUnsafeAccessor(tree()); }
662 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
668 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
674 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
681 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
684 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
693 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
702 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
705 void pruneGrid(
float tolerance = 0.0)
override;
707 #if OPENVDB_ABI_VERSION_NUMBER >= 3 735 template<
typename OtherTreeType>
750 template<
typename OtherTreeType>
763 template<
typename OtherTreeType>
772 CoordBBox evalActiveVoxelBoundingBox()
const override;
774 Coord evalActiveVoxelDim()
const override;
785 TreePtrType treePtr() {
return mTree; }
793 TreeType& tree() {
return *mTree; }
811 void newTree()
override;
819 void readTopology(std::istream&)
override;
822 void writeTopology(std::ostream&)
const override;
825 void readBuffers(std::istream&)
override;
826 #if OPENVDB_ABI_VERSION_NUMBER >= 3 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>
1153 mTree(new
TreeType(other.constTree()))
1158 #if OPENVDB_ABI_VERSION_NUMBER <= 3 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 #if OPENVDB_ABI_VERSION_NUMBER <= 3 1224 template<
typename TreeT>
1229 switch (treePolicy) {
1235 ret.reset(
new Grid(*
this));
1245 template<
typename TreeT>
1249 return this->copy(treePolicy);
1252 #else // if OPENVDB_ABI_VERSION_NUMBER > 3 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>
1298 return this->copyWithNewTree();
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>
1324 mTree.reset(
new TreeType(this->background()));
1331 template<
typename TreeT>
1335 tree().sparseFill(bbox, value, active);
1339 template<
typename TreeT>
1343 this->sparseFill(bbox, value, active);
1346 template<
typename TreeT>
1350 tree().denseFill(bbox, value, active);
1353 template<
typename TreeT>
1357 this->tree().prune(
ValueType(zeroVal<ValueType>() + tolerance));
1360 #if OPENVDB_ABI_VERSION_NUMBER >= 3 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>
1446 tree().readTopology(is, saveFloatAsHalf());
1450 template<
typename TreeT>
1454 tree().writeTopology(os, saveFloatAsHalf());
1458 template<
typename TreeT>
1463 tree().readBuffers(is, saveFloatAsHalf());
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);
1472 tree().readBuffers(is, saveFloatAsHalf());
1478 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1482 template<
typename TreeT>
1487 tree().readBuffers(is, bbox, saveFloatAsHalf());
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);
1496 tree().readBuffers(is, saveFloatAsHalf());
1505 template<
typename TreeT>
1509 tree().readNonresidentBuffers();
1515 template<
typename TreeT>
1519 if (!hasMultiPassIO()) {
1520 tree().writeBuffers(os, saveFloatAsHalf());
1525 uint16_t numPasses = 1;
1526 meta->setCountingPasses(
true);
1528 tree().writeBuffers(os, saveFloatAsHalf());
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);
1537 tree().writeBuffers(os, saveFloatAsHalf());
1544 template<
typename TreeT>
1552 template<
typename TreeT>
1556 tree().print(os, verboseLevel);
1558 if (metaCount() > 0) {
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;
1571 transform().print(os,
" ");
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 GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:454
typename TreeType::ValueType ValueType
Definition: Grid.h:955
_TreeType TreeType
Definition: Grid.h:975
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:621
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1026
Index64 memUsage() const override
Definition: Grid.h:778
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:958
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:442
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:1428
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1112
static TreeType & tree(TreeType &t)
Definition: Grid.h:990
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:506
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:863
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:264
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:967
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:530
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1123
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1517
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
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
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:664
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:513
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 TreeType & constTree(GridType &g)
Definition: Grid.h:995
uint64_t Index64
Definition: Types.h:59
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1363
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:443
MergePolicy
Definition: Types.h:320
_TreeType TreeType
Definition: Grid.h:945
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1418
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 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
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:986
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1581
_TreeType TreeType
Definition: Grid.h:1004
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:954
Definition: Exceptions.h:90
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
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:1606
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:294
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:978
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:949
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:448
VecType
Definition: Types.h:297
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:410
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 TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:948
Ptr(*)() GridFactory
Definition: Grid.h:110
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1186
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1028
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:440
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:108
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
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:437
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:402
static const TreeType & tree(const GridType &g)
Definition: Grid.h:993
static const char *const META_GRID_CLASS
Definition: Grid.h:291
static const char *const META_GRID_NAME
Definition: Grid.h:293
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1006
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:166
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:108
GridNamePred(const Name &_name)
Definition: Grid.h:461
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:994
~GridBase() override
Definition: Grid.h:113
Name name
Definition: Grid.h:463
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
Definition: ValueAccessor.h:219
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1016
static const char *const META_VECTOR_TYPE
Definition: Grid.h:296
Vec3< double > Vec3d
Definition: Vec3.h:679
typename GridType::Ptr GridPtrType
Definition: Grid.h:952
typename GridType::Ptr GridPtrType
Definition: Grid.h:1011
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:976
SharedPtr< TreeBase > Ptr
Definition: Tree.h:65
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:359
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:449
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1355
Base class for typed trees.
Definition: Tree.h:62
static const TreeType & constTree(GridType &g)
Definition: Grid.h:965
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:340
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
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:992
_TreeType TreeType
Definition: Grid.h:505
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:797
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
typename TreeType::Ptr TreePtrType
Definition: Grid.h:977
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:445
static TreeType & tree(GridType &g)
Definition: Grid.h:991
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
GridClass
Definition: Types.h:267
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:798
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:300
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:514
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1027
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:462
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
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:629
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
~Grid() override
Definition: Grid.h:574
static TreeType & tree(GridType &g)
Definition: Grid.h:961
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:966
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:413
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:520
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:511
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1025
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1017
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
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
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 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
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:671
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:956
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1007
Definition: LeafBuffer.h:67
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:515
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1021
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 newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1322
Definition: Exceptions.h:91
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:279
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 const char *const META_FILE_BBOX_MIN
Definition: Grid.h:297
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1008
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:157
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:275
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1043
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
static TreeType & tree(TreeType &t)
Definition: Grid.h:960
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:505
typename _TreeType::ValueType ValueType
Definition: Grid.h:508
Definition: Exceptions.h:39
typename TreeType::ValueType ValueType
Definition: Grid.h:1014
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:66
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
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:770
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...
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1015
static const char *const META_GRID_CREATOR
Definition: Grid.h:292
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:453
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:299
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:447
double Real
Definition: Types.h:66
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:452
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
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:964
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:507
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
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
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:438
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:677
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:295
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:953
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
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
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1012
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:368
std::string Name
Definition: Name.h:44
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:631
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1013
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:670
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:789
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:400
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 const TreeType & constTree(const TreeType &t)
Definition: Grid.h:996
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:518
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:676
std::shared_ptr< T > SharedPtr
Definition: Types.h:134
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
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:187
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
static TreeType & tree(GridType &g)
Definition: Grid.h:1020
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:799
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 ...
typename TreeType::Ptr TreePtrType
Definition: Grid.h:947
static TreeType & tree(TreeType &t)
Definition: Grid.h:1019
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:444
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1410
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:979
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:301
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:521
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:364
static const TreeType & tree(const GridType &g)
Definition: Grid.h:963
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:997
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:983
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:962
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:362
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1554
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:649
Definition: version.h:232
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
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:626
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
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:439
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 TreeType::ValueType ValueType
Definition: Grid.h:985
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1460
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:459
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
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:946
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:957
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:614
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:516
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:339
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:519
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
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
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
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:984
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1005
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:988
typename GridType::Ptr GridPtrType
Definition: Grid.h:982
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:852
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:987
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1024
typename _TreeType::BuildType BuildType
Definition: Grid.h:509
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:665
SharedPtr< Grid > Ptr
Definition: Grid.h:502
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
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1022
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:854
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:612
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:450
tree::TreeBase TreeBase
Definition: Grid.h:53
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:455
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:512