OpenVDB: Grid.h Source File

OpenVDB 7.0.0

Grid.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #ifndef OPENVDB_GRID_HAS_BEEN_INCLUDED
5 #define OPENVDB_GRID_HAS_BEEN_INCLUDED
6
7 #include "Exceptions.h"
8 #include "MetaMap.h"
9 #include "Types.h"
10 #include "io/io.h"
11 #include "math/Transform.h"
12 #include "tree/Tree.h"
13 #include "util/logging.h"
14 #include "util/Name.h"
15 #include <cassert>
16 #include <iostream>
17 #include <set>
18 #include <type_traits>
19 #include <vector>
20
21
22 namespace openvdb {
23 OPENVDB_USE_VERSION_NAMESPACE
24 namespace OPENVDB_VERSION_NAME {
25
26 using TreeBase = tree::TreeBase;
27
28 template<typename> class Grid; // forward declaration
29
30
35 template<typename GridType>
36 inline typename GridType::Ptr createGrid(const typename GridType::ValueType& background);
37
38
42 template<typename GridType>
43 inline typename GridType::Ptr createGrid();
44
45
50 template<typename TreePtrType>
51 inline typename Grid<typename TreePtrType::element_type>::Ptr createGrid(TreePtrType);
52
53
68 template<typename GridType>
69 typename GridType::Ptr createLevelSet(
70 Real voxelSize = 1.0, Real halfWidth = LEVEL_SET_HALF_WIDTH);
71
72
74
75
77 class OPENVDB_API GridBase: public MetaMap
78 {
79 public:
80 using Ptr = SharedPtr<GridBase>;
81 using ConstPtr = SharedPtr<const GridBase>;
82
83 using GridFactory = Ptr (*)();
84
85
86 ~GridBase() override {}
87
88
91
94 virtual GridBase::Ptr copyGrid() = 0;
97 virtual GridBase::ConstPtr copyGrid() const = 0;
100 virtual GridBase::Ptr copyGridWithNewTree() const = 0;
101
102 #if OPENVDB_ABI_VERSION_NUMBER >= 7
103 virtual GridBase::ConstPtr copyGridReplacingMetadata(const MetaMap& meta) const = 0;
110 virtual GridBase::ConstPtr copyGridReplacingTransform(math::Transform::Ptr xform) const = 0;
114 virtual GridBase::ConstPtr copyGridReplacingMetadataAndTransform(const MetaMap& meta,
115 math::Transform::Ptr xform) const = 0;
116 #endif
117
119 virtual GridBase::Ptr deepCopyGrid() const = 0;
120
122
123
126
128 static Ptr createGrid(const Name& type);
129
131 static bool isRegistered(const Name &type);
132
134 static void clearRegistry();
135
137
140
142 virtual Name type() const = 0;
144 virtual Name valueType() const = 0;
145
147 template<typename GridType>
148 bool isType() const { return (this->type() == GridType::gridType()); }
149
151
153 template<typename GridType>
156 static typename GridType::Ptr grid(const GridBase::Ptr&);
157 template<typename GridType>
158 static typename GridType::ConstPtr grid(const GridBase::ConstPtr&);
159 template<typename GridType>
160 static typename GridType::ConstPtr constGrid(const GridBase::Ptr&);
161 template<typename GridType>
162 static typename GridType::ConstPtr constGrid(const GridBase::ConstPtr&);
164
167
170 TreeBase::Ptr baseTreePtr();
173 TreeBase::ConstPtr baseTreePtr() const { return this->constBaseTreePtr(); }
176 virtual TreeBase::ConstPtr constBaseTreePtr() const = 0;
177
182 TreeBase& baseTree() { return const_cast<TreeBase&>(this->constBaseTree()); }
187 const TreeBase& baseTree() const { return this->constBaseTree(); }
192 const TreeBase& constBaseTree() const { return *(this->constBaseTreePtr()); }
193
200 virtual void setTree(TreeBase::Ptr) = 0;
201
203 virtual void newTree() = 0;
204
206
208 virtual bool empty() const = 0;
210 virtual void clear() = 0;
211
212
215
221 virtual void pruneGrid(float tolerance = 0.0) = 0;
222
227 void clipGrid(const BBoxd&);
228
233 virtual void clip(const CoordBBox&) = 0;
234
236
261 template<typename GridTypeListT, typename OpT> inline bool apply(OpT&) const;
262 template<typename GridTypeListT, typename OpT> inline bool apply(OpT&);
263 template<typename GridTypeListT, typename OpT> inline bool apply(const OpT&) const;
264 template<typename GridTypeListT, typename OpT> inline bool apply(const OpT&);
266
269
271 std::string getName() const;
273 void setName(const std::string&);
274
276 std::string getCreator() const;
278 void setCreator(const std::string&);
279
282 bool saveFloatAsHalf() const;
283 void setSaveFloatAsHalf(bool);
284
288 GridClass getGridClass() const;
292 void setGridClass(GridClass);
294 void clearGridClass();
295
297
299 static std::string gridClassToString(GridClass);
301 static std::string gridClassToMenuName(GridClass);
306 static GridClass stringToGridClass(const std::string&);
307
310
314 VecType getVectorType() const;
318 void setVectorType(VecType);
320 void clearVectorType();
321
323
325 static std::string vecTypeToString(VecType);
328 static std::string vecTypeExamples(VecType);
331 static std::string vecTypeDescription(VecType);
332 static VecType stringToVecType(const std::string&);
333
336
340 bool isInWorldSpace() const;
342 void setIsInWorldSpace(bool);
343
345
346 // Standard metadata field names
347 // (These fields should normally not be accessed directly, but rather
348 // via the accessor methods above, when available.)
349 // Note: Visual C++ requires these declarations to be separate statements.
350 static const char* const META_GRID_CLASS;
351 static const char* const META_GRID_CREATOR;
352 static const char* const META_GRID_NAME;
353 static const char* const META_SAVE_HALF_FLOAT;
354 static const char* const META_IS_LOCAL_SPACE;
355 static const char* const META_VECTOR_TYPE;
356 static const char* const META_FILE_BBOX_MIN;
357 static const char* const META_FILE_BBOX_MAX;
358 static const char* const META_FILE_COMPRESSION;
359 static const char* const META_FILE_MEM_BYTES;
360 static const char* const META_FILE_VOXEL_COUNT;
361 static const char* const META_FILE_DELAYED_LOAD;
362
363
366
368 virtual Index64 activeVoxelCount() const = 0;
369
372 virtual CoordBBox evalActiveVoxelBoundingBox() const = 0;
373
375 virtual Coord evalActiveVoxelDim() const = 0;
376
378 virtual Index64 memUsage() const = 0;
379
384 void addStatsMetadata();
390 MetaMap::Ptr getStatsMetadata() const;
391
393
394
397
399 math::Transform::Ptr transformPtr() { return mTransform; }
402 math::Transform::ConstPtr transformPtr() const { return mTransform; }
403 math::Transform::ConstPtr constTransformPtr() const { return mTransform; }
405
406 math::Transform& transform() { return *mTransform; }
411 const math::Transform& transform() const { return *mTransform; }
412 const math::Transform& constTransform() const { return *mTransform; }
414
416
419
426 void setTransform(math::Transform::Ptr);
427
429 Vec3d voxelSize() const { return transform().voxelSize(); }
432 Vec3d voxelSize(const Vec3d& xyz) const { return transform().voxelSize(xyz); }
434 bool hasUniformVoxels() const { return mTransform->hasUniformScale(); }
436 Vec3d indexToWorld(const Vec3d& xyz) const { return transform().indexToWorld(xyz); }
438 Vec3d indexToWorld(const Coord& ijk) const { return transform().indexToWorld(ijk); }
440 Vec3d worldToIndex(const Vec3d& xyz) const { return transform().worldToIndex(xyz); }
441
443
444
447
450 virtual void readTopology(std::istream&) = 0;
453 virtual void writeTopology(std::ostream&) const = 0;
454
456 virtual void readBuffers(std::istream&) = 0;
458 virtual void readBuffers(std::istream&, const CoordBBox&) = 0;
464 virtual void readNonresidentBuffers() const = 0;
466 virtual void writeBuffers(std::ostream&) const = 0;
467
469 void readTransform(std::istream& is) { transform().read(is); }
471 void writeTransform(std::ostream& os) const { transform().write(os); }
472
474 virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const = 0;
475
477
478
479 protected:
481 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
482
483 #if OPENVDB_ABI_VERSION_NUMBER >= 7
484 GridBase(const MetaMap& meta, math::Transform::Ptr xform);
487 #endif
488
490 GridBase(const GridBase& other): MetaMap(other), mTransform(other.mTransform->copy()) {}
491
493 GridBase(GridBase& other, ShallowCopy): MetaMap(other), mTransform(other.mTransform) {}
494
496 static void registerGrid(const Name& type, GridFactory);
498 static void unregisterGrid(const Name& type);
499
500
501 private:
502 math::Transform::Ptr mTransform;
503 }; // class GridBase
504
505
507
508
509 using GridPtrVec = std::vector<GridBase::Ptr>;
510 using GridPtrVecIter = GridPtrVec::iterator;
511 using GridPtrVecCIter = GridPtrVec::const_iterator;
512 using GridPtrVecPtr = SharedPtr<GridPtrVec>;
513
514 using GridCPtrVec = std::vector<GridBase::ConstPtr>;
515 using GridCPtrVecIter = GridCPtrVec::iterator;
516 using GridCPtrVecCIter = GridCPtrVec::const_iterator;
517 using GridCPtrVecPtr = SharedPtr<GridCPtrVec>;
518
519 using GridPtrSet = std::set<GridBase::Ptr>;
520 using GridPtrSetIter = GridPtrSet::iterator;
521 using GridPtrSetCIter = GridPtrSet::const_iterator;
522 using GridPtrSetPtr = SharedPtr<GridPtrSet>;
523
524 using GridCPtrSet = std::set<GridBase::ConstPtr>;
525 using GridCPtrSetIter = GridCPtrSet::iterator;
526 using GridCPtrSetCIter = GridCPtrSet::const_iterator;
527 using GridCPtrSetPtr = SharedPtr<GridCPtrSet>;
528
529
531 struct OPENVDB_API GridNamePred
532 {
533 GridNamePred(const Name& _name): name(_name) {}
534 bool operator()(const GridBase::ConstPtr& g) const { return g && g->getName() == name; }
535 Name name;
536 };
537
539 template<typename GridPtrContainerT>
540 inline typename GridPtrContainerT::value_type
541 findGridByName(const GridPtrContainerT& container, const Name& name)
542 {
543 using GridPtrT = typename GridPtrContainerT::value_type;
544 typename GridPtrContainerT::const_iterator it =
545 std::find_if(container.begin(), container.end(), GridNamePred(name));
546 return (it == container.end() ? GridPtrT() : *it);
547 }
548
550 template<typename KeyT, typename GridPtrT>
551 inline GridPtrT
552 findGridByName(const std::map<KeyT, GridPtrT>& container, const Name& name)
553 {
554 using GridPtrMapT = std::map<KeyT, GridPtrT>;
555 for (typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
556 it != end; ++it)
557 {
558 const GridPtrT& grid = it->second;
559 if (grid && grid->getName() == name) return grid;
560 }
561 return GridPtrT();
562 }
564
565
567
568
570 template<typename _TreeType>
571 class Grid: public GridBase
572 {
573 public:
574 using Ptr = SharedPtr<Grid>;
575 using ConstPtr = SharedPtr<const Grid>;
576
577 using TreeType = _TreeType;
578 using TreePtrType = typename _TreeType::Ptr;
579 using ConstTreePtrType = typename _TreeType::ConstPtr;
580 using ValueType = typename _TreeType::ValueType;
581 using BuildType = typename _TreeType::BuildType;
582
583 using ValueOnIter = typename _TreeType::ValueOnIter;
584 using ValueOnCIter = typename _TreeType::ValueOnCIter;
585 using ValueOffIter = typename _TreeType::ValueOffIter;
586 using ValueOffCIter = typename _TreeType::ValueOffCIter;
587 using ValueAllIter = typename _TreeType::ValueAllIter;
588 using ValueAllCIter = typename _TreeType::ValueAllCIter;
589
590 using Accessor = typename tree::ValueAccessor<_TreeType, true>;
591 using ConstAccessor = typename tree::ValueAccessor<const _TreeType, true>;
592 using UnsafeAccessor = typename tree::ValueAccessor<_TreeType, false>;
593 using ConstUnsafeAccessor = typename tree::ValueAccessor<const _TreeType, false>;
594
601 template<typename OtherValueType>
602 struct ValueConverter {
603 using Type = Grid<typename TreeType::template ValueConverter<OtherValueType>::Type>;
604 };
605
607 static Ptr create(const ValueType& background);
609 static Ptr create();
612 static Ptr create(TreePtrType);
615 static Ptr create(const GridBase& other);
616
617
619 Grid();
621 explicit Grid(const ValueType& background);
625 explicit Grid(TreePtrType);
627 Grid(const Grid&);
633 template<typename OtherTreeType>
634 explicit Grid(const Grid<OtherTreeType>&);
636 Grid(Grid&, ShallowCopy);
639 explicit Grid(const GridBase&);
640
641 ~Grid() override {}
642
644 Grid& operator=(const Grid&) = delete;
645
648
651 Ptr copy();
654 ConstPtr copy() const;
657 Ptr copyWithNewTree() const;
658
661 GridBase::Ptr copyGrid() override;
664 GridBase::ConstPtr copyGrid() const override;
667 GridBase::Ptr copyGridWithNewTree() const override;
669
672
673 #if OPENVDB_ABI_VERSION_NUMBER >= 7
674 ConstPtr copyReplacingMetadata(const MetaMap& meta) const;
681 ConstPtr copyReplacingTransform(math::Transform::Ptr xform) const;
685 ConstPtr copyReplacingMetadataAndTransform(const MetaMap& meta,
686 math::Transform::Ptr xform) const;
687
690 GridBase::ConstPtr copyGridReplacingMetadata(const MetaMap& meta) const override;
695 GridBase::ConstPtr copyGridReplacingTransform(math::Transform::Ptr xform) const override;
699 GridBase::ConstPtr copyGridReplacingMetadataAndTransform(const MetaMap& meta,
700 math::Transform::Ptr xform) const override;
701 #endif
702
704 Ptr deepCopy() const { return Ptr(new Grid(*this)); }
706 GridBase::Ptr deepCopyGrid() const override { return this->deepCopy(); }
707
709
710
712 Name type() const override { return this->gridType(); }
714 static Name gridType() { return TreeType::treeType(); }
715
717 Name valueType() const override { return tree().valueType(); }
718
719
722
725 const ValueType& background() const { return mTree->background(); }
726
728 bool empty() const override { return tree().empty(); }
730 void clear() override { tree().clear(); }
731
735 Accessor getAccessor() { return Accessor(tree()); }
743 UnsafeAccessor getUnsafeAccessor() { return UnsafeAccessor(tree()); }
745 ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
747 ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
755 ConstUnsafeAccessor getConstUnsafeAccessor() const { return ConstUnsafeAccessor(tree()); }
756
758 ValueOnIter beginValueOn() { return tree().beginValueOn(); }
760 ValueOnCIter beginValueOn() const { return tree().cbeginValueOn(); }
762 ValueOnCIter cbeginValueOn() const { return tree().cbeginValueOn(); }
764 ValueOffIter beginValueOff() { return tree().beginValueOff(); }
766 ValueOffCIter beginValueOff() const { return tree().cbeginValueOff(); }
768 ValueOffCIter cbeginValueOff() const { return tree().cbeginValueOff(); }
770 ValueAllIter beginValueAll() { return tree().beginValueAll(); }
772 ValueAllCIter beginValueAll() const { return tree().cbeginValueAll(); }
774 ValueAllCIter cbeginValueAll() const { return tree().cbeginValueAll(); }
775
777
780
789 void sparseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
798 void fill(const CoordBBox& bbox, const ValueType& value, bool active = true);
799
806 void denseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
807
809 void pruneGrid(float tolerance = 0.0) override;
810
815 void clip(const CoordBBox&) override;
816
822 void merge(Grid& other, MergePolicy policy = MERGE_ACTIVE_STATES);
823
837 template<typename OtherTreeType>
838 void topologyUnion(const Grid<OtherTreeType>& other);
839
852 template<typename OtherTreeType>
853 void topologyIntersection(const Grid<OtherTreeType>& other);
854
865 template<typename OtherTreeType>
866 void topologyDifference(const Grid<OtherTreeType>& other);
867
869
872
874 Index64 activeVoxelCount() const override { return tree().activeVoxelCount(); }
876 CoordBBox evalActiveVoxelBoundingBox() const override;
878 Coord evalActiveVoxelDim() const override;
880 void evalMinMax(ValueType& minVal, ValueType& maxVal) const;
881
884 Index64 memUsage() const override { return tree().memUsage(); }
885
887
888
891
893 TreePtrType treePtr() { return mTree; }
896 ConstTreePtrType treePtr() const { return mTree; }
897 ConstTreePtrType constTreePtr() const { return mTree; }
898 TreeBase::ConstPtr constBaseTreePtr() const override { return mTree; }
900
901 TreeType& tree() { return *mTree; }
906 const TreeType& tree() const { return *mTree; }
907 const TreeType& constTree() const { return *mTree; }
909
911
914
920 void setTree(TreeBase::Ptr) override;
921
924 void newTree() override;
925
927
928
931
934 void readTopology(std::istream&) override;
937 void writeTopology(std::ostream&) const override;
938
940 void readBuffers(std::istream&) override;
942 void readBuffers(std::istream&, const CoordBBox&) override;
948 void readNonresidentBuffers() const override;
950 void writeBuffers(std::ostream&) const override;
951
953 void print(std::ostream& = std::cout, int verboseLevel = 1) const override;
954
956
960 static inline bool hasMultiPassIO();
961
962
965
967 static bool isRegistered() { return GridBase::isRegistered(Grid::gridType()); }
969 static void registerGrid()
970 {
971 GridBase::registerGrid(Grid::gridType(), Grid::factory);
972 if (!tree::internal::LeafBufferFlags<ValueType>::IsAtomic) {
973 OPENVDB_LOG_WARN("delayed loading of grids of type " << Grid::gridType()
974 << " might not be threadsafe on this platform");
975 }
976 }
978 static void unregisterGrid() { GridBase::unregisterGrid(Grid::gridType()); }
979
981
982
983 private:
984 #if OPENVDB_ABI_VERSION_NUMBER >= 7
985 Grid(TreePtrType tree, const MetaMap& meta, math::Transform::Ptr xform);
987 #endif
988
990 static GridBase::Ptr factory() { return Grid::create(); }
991
992 TreePtrType mTree;
993 }; // class Grid
994
995
997
998
1006 template<typename GridType>
1007 inline typename GridType::Ptr
1008 gridPtrCast(const GridBase::Ptr& grid)
1009 {
1010 return GridBase::grid<GridType>(grid);
1011 }
1012
1013
1022 template<typename GridType>
1023 inline typename GridType::ConstPtr
1024 gridConstPtrCast(const GridBase::ConstPtr& grid)
1025 {
1026 return GridBase::constGrid<GridType>(grid);
1027 }
1028
1029
1031
1032
1039 template<typename GridType>
1040 inline typename GridType::Ptr
1041 deepCopyTypedGrid(const GridBase::ConstPtr& grid)
1042 {
1043 if (!grid || !grid->isType<GridType>()) return typename GridType::Ptr();
1044 return gridPtrCast<GridType>(grid->deepCopyGrid());
1045 }
1046
1047
1048 template<typename GridType>
1049 inline typename GridType::Ptr
1050 deepCopyTypedGrid(const GridBase& grid)
1051 {
1052 if (!grid.isType<GridType>()) return typename GridType::Ptr();
1053 return gridPtrCast<GridType>(grid.deepCopyGrid());
1054 }
1056
1057
1059
1060
1062 template<typename _TreeType>
1065 struct TreeAdapter
1066 {
1067 using TreeType = _TreeType;
1068 using NonConstTreeType = typename std::remove_const<TreeType>::type;
1069 using TreePtrType = typename TreeType::Ptr;
1070 using ConstTreePtrType = typename TreeType::ConstPtr;
1071 using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1072 using GridType = Grid<TreeType>;
1073 using NonConstGridType = Grid<NonConstTreeType>;
1074 using GridPtrType = typename GridType::Ptr;
1075 using NonConstGridPtrType = typename NonConstGridType::Ptr;
1076 using ConstGridPtrType = typename GridType::ConstPtr;
1077 using ValueType = typename TreeType::ValueType;
1078 using AccessorType = typename tree::ValueAccessor<TreeType>;
1079 using ConstAccessorType = typename tree::ValueAccessor<const TreeType>;
1080 using NonConstAccessorType = typename tree::ValueAccessor<NonConstTreeType>;
1081
1082 static TreeType& tree(TreeType& t) { return t; }
1083 static TreeType& tree(GridType& g) { return g.tree(); }
1084 static const TreeType& tree(const TreeType& t) { return t; }
1085 static const TreeType& tree(const GridType& g) { return g.tree(); }
1086 static const TreeType& constTree(TreeType& t) { return t; }
1087 static const TreeType& constTree(GridType& g) { return g.constTree(); }
1088 static const TreeType& constTree(const TreeType& t) { return t; }
1089 static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1090 };
1091
1092
1094 template<typename _TreeType>
1095 struct TreeAdapter<Grid<_TreeType> >
1096 {
1097 using TreeType = _TreeType;
1098 using NonConstTreeType = typename std::remove_const<TreeType>::type;
1099 using TreePtrType = typename TreeType::Ptr;
1100 using ConstTreePtrType = typename TreeType::ConstPtr;
1101 using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1102 using GridType = Grid<TreeType>;
1103 using NonConstGridType = Grid<NonConstTreeType>;
1104 using GridPtrType = typename GridType::Ptr;
1105 using NonConstGridPtrType = typename NonConstGridType::Ptr;
1106 using ConstGridPtrType = typename GridType::ConstPtr;
1107 using ValueType = typename TreeType::ValueType;
1108 using AccessorType = typename tree::ValueAccessor<TreeType>;
1109 using ConstAccessorType = typename tree::ValueAccessor<const TreeType>;
1110 using NonConstAccessorType = typename tree::ValueAccessor<NonConstTreeType>;
1111
1112 static TreeType& tree(TreeType& t) { return t; }
1113 static TreeType& tree(GridType& g) { return g.tree(); }
1114 static const TreeType& tree(const TreeType& t) { return t; }
1115 static const TreeType& tree(const GridType& g) { return g.tree(); }
1116 static const TreeType& constTree(TreeType& t) { return t; }
1117 static const TreeType& constTree(GridType& g) { return g.constTree(); }
1118 static const TreeType& constTree(const TreeType& t) { return t; }
1119 static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1120 };
1121
1123 template<typename _TreeType>
1124 struct TreeAdapter<tree::ValueAccessor<_TreeType> >
1125 {
1126 using TreeType = _TreeType;
1127 using NonConstTreeType = typename std::remove_const<TreeType>::type;
1128 using TreePtrType = typename TreeType::Ptr;
1129 using ConstTreePtrType = typename TreeType::ConstPtr;
1130 using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1131 using GridType = Grid<TreeType>;
1132 using NonConstGridType = Grid<NonConstTreeType>;
1133 using GridPtrType = typename GridType::Ptr;
1134 using NonConstGridPtrType = typename NonConstGridType::Ptr;
1135 using ConstGridPtrType = typename GridType::ConstPtr;
1136 using ValueType = typename TreeType::ValueType;
1137 using AccessorType = typename tree::ValueAccessor<TreeType>;
1138 using ConstAccessorType = typename tree::ValueAccessor<const TreeType>;
1139 using NonConstAccessorType = typename tree::ValueAccessor<NonConstTreeType>;
1140
1141 static TreeType& tree(TreeType& t) { return t; }
1142 static TreeType& tree(GridType& g) { return g.tree(); }
1143 static TreeType& tree(AccessorType& a) { return a.tree(); }
1144 static const TreeType& tree(const TreeType& t) { return t; }
1145 static const TreeType& tree(const GridType& g) { return g.tree(); }
1146 static const TreeType& tree(const AccessorType& a) { return a.tree(); }
1147 static const TreeType& constTree(TreeType& t) { return t; }
1148 static const TreeType& constTree(GridType& g) { return g.constTree(); }
1149 static const TreeType& constTree(const TreeType& t) { return t; }
1150 static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1151 };
1152
1154
1155
1157
1158
1164 template<typename LeafNodeType>
1165 struct HasMultiPassIO {
1166 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1167 };
1168
1169 // Partial specialization for Tree types
1170 template<typename RootNodeType>
1171 struct HasMultiPassIO<tree::Tree<RootNodeType>> {
1172 // A tree is multi-pass if its (root node's) leaf node type is multi-pass.
1173 static const bool value = HasMultiPassIO<typename RootNodeType::LeafNodeType>::value;
1174 };
1175
1176 // Partial specialization for Grid types
1177 template<typename TreeType>
1178 struct HasMultiPassIO<Grid<TreeType>> {
1179 // A grid is multi-pass if its tree's leaf node type is multi-pass.
1180 static const bool value = HasMultiPassIO<typename TreeType::LeafNodeType>::value;
1181 };
1182
1183
1185
1186 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1187 inline GridBase::GridBase(const MetaMap& meta, math::Transform::Ptr xform)
1188 : MetaMap(meta)
1189 , mTransform(xform)
1190 {
1191 if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
1192 }
1193 #endif
1194
1195 template<typename GridType>
1196 inline typename GridType::Ptr
1197 GridBase::grid(const GridBase::Ptr& grid)
1198 {
1199 // The string comparison on type names is slower than a dynamic pointer cast, but
1200 // it is safer when pointers cross DSO boundaries, as they do in many Houdini nodes.
1201 if (grid && grid->type() == GridType::gridType()) {
1202 return StaticPtrCast<GridType>(grid);
1203 }
1204 return typename GridType::Ptr();
1205 }
1206
1207
1208 template<typename GridType>
1209 inline typename GridType::ConstPtr
1210 GridBase::grid(const GridBase::ConstPtr& grid)
1211 {
1212 return ConstPtrCast<const GridType>(
1213 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1214 }
1215
1216
1217 template<typename GridType>
1218 inline typename GridType::ConstPtr
1219 GridBase::constGrid(const GridBase::Ptr& grid)
1220 {
1221 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(grid));
1222 }
1223
1224
1225 template<typename GridType>
1226 inline typename GridType::ConstPtr
1227 GridBase::constGrid(const GridBase::ConstPtr& grid)
1228 {
1229 return ConstPtrCast<const GridType>(
1230 GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1231 }
1232
1233
1234 inline TreeBase::Ptr
1235 GridBase::baseTreePtr()
1236 {
1237 return ConstPtrCast<TreeBase>(this->constBaseTreePtr());
1238 }
1239
1240
1241 inline void
1242 GridBase::setTransform(math::Transform::Ptr xform)
1243 {
1244 if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
1245 mTransform = xform;
1246 }
1247
1248
1250
1251
1252 template<typename TreeT>
1253 inline Grid<TreeT>::Grid(): mTree(new TreeType)
1254 {
1255 }
1256
1257
1258 template<typename TreeT>
1259 inline Grid<TreeT>::Grid(const ValueType &background): mTree(new TreeType(background))
1260 {
1261 }
1262
1263
1264 template<typename TreeT>
1265 inline Grid<TreeT>::Grid(TreePtrType tree): mTree(tree)
1266 {
1267 if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1268 }
1269
1270
1271 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1272 template<typename TreeT>
1273 inline Grid<TreeT>::Grid(TreePtrType tree, const MetaMap& meta, math::Transform::Ptr xform):
1274 GridBase(meta, xform),
1275 mTree(tree)
1276 {
1277 if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1278 }
1279 #endif
1280
1281
1282 template<typename TreeT>
1283 inline Grid<TreeT>::Grid(const Grid& other):
1284 GridBase(other),
1285 mTree(StaticPtrCast<TreeType>(other.mTree->copy()))
1286 {
1287 }
1288
1289
1290 template<typename TreeT>
1291 template<typename OtherTreeType>
1292 inline Grid<TreeT>::Grid(const Grid<OtherTreeType>& other):
1293 GridBase(other),
1294 mTree(new TreeType(other.constTree()))
1295 {
1296 }
1297
1298
1299 template<typename TreeT>
1300 inline Grid<TreeT>::Grid(Grid& other, ShallowCopy):
1301 GridBase(other),
1302 mTree(other.mTree)
1303 {
1304 }
1305
1306
1307 template<typename TreeT>
1308 inline Grid<TreeT>::Grid(const GridBase& other):
1309 GridBase(other),
1310 mTree(new TreeType)
1311 {
1312 }
1313
1314
1315 //static
1316 template<typename TreeT>
1317 inline typename Grid<TreeT>::Ptr
1318 Grid<TreeT>::create()
1319 {
1320 return Grid::create(zeroVal<ValueType>());
1321 }
1322
1323
1324 //static
1325 template<typename TreeT>
1326 inline typename Grid<TreeT>::Ptr
1327 Grid<TreeT>::create(const ValueType& background)
1328 {
1329 return Ptr(new Grid(background));
1330 }
1331
1332
1333 //static
1334 template<typename TreeT>
1335 inline typename Grid<TreeT>::Ptr
1336 Grid<TreeT>::create(TreePtrType tree)
1337 {
1338 return Ptr(new Grid(tree));
1339 }
1340
1341
1342 //static
1343 template<typename TreeT>
1344 inline typename Grid<TreeT>::Ptr
1345 Grid<TreeT>::create(const GridBase& other)
1346 {
1347 return Ptr(new Grid(other));
1348 }
1349
1350
1352
1353
1354 template<typename TreeT>
1355 inline typename Grid<TreeT>::ConstPtr
1356 Grid<TreeT>::copy() const
1357 {
1358 return ConstPtr{new Grid{*const_cast<Grid*>(this), ShallowCopy{}}};
1359 }
1360
1361
1362 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1363 template<typename TreeT>
1364 inline typename Grid<TreeT>::ConstPtr
1365 Grid<TreeT>::copyReplacingMetadata(const MetaMap& meta) const
1366 {
1367 math::Transform::Ptr transformPtr = ConstPtrCast<math::Transform>(
1368 this->constTransformPtr());
1369 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1370 return ConstPtr{new Grid<TreeT>{treePtr, meta, transformPtr}};
1371 }
1372
1373 template<typename TreeT>
1374 inline typename Grid<TreeT>::ConstPtr
1375 Grid<TreeT>::copyReplacingTransform(math::Transform::Ptr xform) const
1376 {
1377 return this->copyReplacingMetadataAndTransform(*this, xform);
1378 }
1379
1380 template<typename TreeT>
1381 inline typename Grid<TreeT>::ConstPtr
1382 Grid<TreeT>::copyReplacingMetadataAndTransform(const MetaMap& meta,
1383 math::Transform::Ptr xform) const
1384 {
1385 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1386 return ConstPtr{new Grid<TreeT>{treePtr, meta, xform}};
1387 }
1388 #endif
1389
1390
1391 template<typename TreeT>
1392 inline typename Grid<TreeT>::Ptr
1393 Grid<TreeT>::copy()
1394 {
1395 return Ptr{new Grid{*this, ShallowCopy{}}};
1396 }
1397
1398
1399 template<typename TreeT>
1400 inline typename Grid<TreeT>::Ptr
1401 Grid<TreeT>::copyWithNewTree() const
1402 {
1403 Ptr result{new Grid{*const_cast<Grid*>(this), ShallowCopy{}}};
1404 result->newTree();
1405 return result;
1406 }
1407
1408
1409 template<typename TreeT>
1410 inline GridBase::Ptr
1411 Grid<TreeT>::copyGrid()
1412 {
1413 return this->copy();
1414 }
1415
1416 template<typename TreeT>
1417 inline GridBase::ConstPtr
1418 Grid<TreeT>::copyGrid() const
1419 {
1420 return this->copy();
1421 }
1422
1423 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1424 template<typename TreeT>
1425 inline GridBase::ConstPtr
1426 Grid<TreeT>::copyGridReplacingMetadata(const MetaMap& meta) const
1427 {
1428 return this->copyReplacingMetadata(meta);
1429 }
1430
1431 template<typename TreeT>
1432 inline GridBase::ConstPtr
1433 Grid<TreeT>::copyGridReplacingTransform(math::Transform::Ptr xform) const
1434 {
1435 return this->copyReplacingTransform(xform);
1436 }
1437
1438 template<typename TreeT>
1439 inline GridBase::ConstPtr
1440 Grid<TreeT>::copyGridReplacingMetadataAndTransform(const MetaMap& meta,
1441 math::Transform::Ptr xform) const
1442 {
1443 return this->copyReplacingMetadataAndTransform(meta, xform);
1444 }
1445 #endif
1446
1447 template<typename TreeT>
1448 inline GridBase::Ptr
1449 Grid<TreeT>::copyGridWithNewTree() const
1450 {
1451 return this->copyWithNewTree();
1452 }
1453
1454
1456
1457
1458 template<typename TreeT>
1459 inline void
1460 Grid<TreeT>::setTree(TreeBase::Ptr tree)
1461 {
1462 if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1463 if (tree->type() != TreeType::treeType()) {
1464 OPENVDB_THROW(TypeError, "Cannot assign a tree of type "
1465 + tree->type() + " to a grid of type " + this->type());
1466 }
1467 mTree = StaticPtrCast<TreeType>(tree);
1468 }
1469
1470
1471 template<typename TreeT>
1472 inline void
1473 Grid<TreeT>::newTree()
1474 {
1475 mTree.reset(new TreeType(this->background()));
1476 }
1477
1478
1480
1481
1482 template<typename TreeT>
1483 inline void
1484 Grid<TreeT>::sparseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1485 {
1486 tree().sparseFill(bbox, value, active);
1487 }
1488
1489
1490 template<typename TreeT>
1491 inline void
1492 Grid<TreeT>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1493 {
1494 this->sparseFill(bbox, value, active);
1495 }
1496
1497 template<typename TreeT>
1498 inline void
1499 Grid<TreeT>::denseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1500 {
1501 tree().denseFill(bbox, value, active);
1502 }
1503
1504 template<typename TreeT>
1505 inline void
1506 Grid<TreeT>::pruneGrid(float tolerance)
1507 {
1508 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
1509 const auto value = zeroVal<ValueType>() + tolerance;
1510 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
1511 this->tree().prune(static_cast<ValueType>(value));
1512 }
1513
1514 template<typename TreeT>
1515 inline void
1516 Grid<TreeT>::clip(const CoordBBox& bbox)
1517 {
1518 tree().clip(bbox);
1519 }
1520
1521 template<typename TreeT>
1522 inline void
1523 Grid<TreeT>::merge(Grid& other, MergePolicy policy)
1524 {
1525 tree().merge(other.tree(), policy);
1526 }
1527
1528
1529 template<typename TreeT>
1530 template<typename OtherTreeType>
1531 inline void
1532 Grid<TreeT>::topologyUnion(const Grid<OtherTreeType>& other)
1533 {
1534 tree().topologyUnion(other.tree());
1535 }
1536
1537
1538 template<typename TreeT>
1539 template<typename OtherTreeType>
1540 inline void
1541 Grid<TreeT>::topologyIntersection(const Grid<OtherTreeType>& other)
1542 {
1543 tree().topologyIntersection(other.tree());
1544 }
1545
1546
1547 template<typename TreeT>
1548 template<typename OtherTreeType>
1549 inline void
1550 Grid<TreeT>::topologyDifference(const Grid<OtherTreeType>& other)
1551 {
1552 tree().topologyDifference(other.tree());
1553 }
1554
1555
1557
1558
1559 template<typename TreeT>
1560 inline void
1561 Grid<TreeT>::evalMinMax(ValueType& minVal, ValueType& maxVal) const
1562 {
1563 tree().evalMinMax(minVal, maxVal);
1564 }
1565
1566
1567 template<typename TreeT>
1568 inline CoordBBox
1569 Grid<TreeT>::evalActiveVoxelBoundingBox() const
1570 {
1571 CoordBBox bbox;
1572 tree().evalActiveVoxelBoundingBox(bbox);
1573 return bbox;
1574 }
1575
1576
1577 template<typename TreeT>
1578 inline Coord
1579 Grid<TreeT>::evalActiveVoxelDim() const
1580 {
1581 Coord dim;
1582 const bool nonempty = tree().evalActiveVoxelDim(dim);
1583 return (nonempty ? dim : Coord());
1584 }
1585
1586
1588
1589
1592
1593 template<typename TreeT>
1594 inline void
1595 Grid<TreeT>::readTopology(std::istream& is)
1596 {
1597 tree().readTopology(is, saveFloatAsHalf());
1598 }
1599
1600
1601 template<typename TreeT>
1602 inline void
1603 Grid<TreeT>::writeTopology(std::ostream& os) const
1604 {
1605 tree().writeTopology(os, saveFloatAsHalf());
1606 }
1607
1608
1609 template<typename TreeT>
1610 inline void
1611 Grid<TreeT>::readBuffers(std::istream& is)
1612 {
1613 if (!hasMultiPassIO() || (io::getFormatVersion(is) < OPENVDB_FILE_VERSION_MULTIPASS_IO)) {
1614 tree().readBuffers(is, saveFloatAsHalf());
1615 } else {
1616 uint16_t numPasses = 1;
1617 is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
1618 const io::StreamMetadata::Ptr meta = io::getStreamMetadataPtr(is);
1619 assert(bool(meta));
1620 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1621 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1622 meta->setPass(pass);
1623 tree().readBuffers(is, saveFloatAsHalf());
1624 }
1625 }
1626 }
1627
1628
1631 template<typename TreeT>
1632 inline void
1633 Grid<TreeT>::readBuffers(std::istream& is, const CoordBBox& bbox)
1634 {
1635 if (!hasMultiPassIO() || (io::getFormatVersion(is) < OPENVDB_FILE_VERSION_MULTIPASS_IO)) {
1636 tree().readBuffers(is, bbox, saveFloatAsHalf());
1637 } else {
1638 uint16_t numPasses = 1;
1639 is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
1640 const io::StreamMetadata::Ptr meta = io::getStreamMetadataPtr(is);
1641 assert(bool(meta));
1642 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1643 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1644 meta->setPass(pass);
1645 tree().readBuffers(is, saveFloatAsHalf());
1646 }
1647 // Cannot clip inside readBuffers() when using multiple passes,
1648 // so instead clip afterwards.
1649 tree().clip(bbox);
1650 }
1651 }
1652
1653
1654 template<typename TreeT>
1655 inline void
1656 Grid<TreeT>::readNonresidentBuffers() const
1657 {
1658 tree().readNonresidentBuffers();
1659 }
1660
1661
1662 template<typename TreeT>
1663 inline void
1664 Grid<TreeT>::writeBuffers(std::ostream& os) const
1665 {
1666 if (!hasMultiPassIO()) {
1667 tree().writeBuffers(os, saveFloatAsHalf());
1668 } else {
1669 // Determine how many leaf buffer passes are required for this grid
1670 const io::StreamMetadata::Ptr meta = io::getStreamMetadataPtr(os);
1671 assert(bool(meta));
1672 uint16_t numPasses = 1;
1673 meta->setCountingPasses(true);
1674 meta->setPass(0);
1675 tree().writeBuffers(os, saveFloatAsHalf());
1676 numPasses = static_cast<uint16_t>(meta->pass());
1677 os.write(reinterpret_cast<const char*>(&numPasses), sizeof(uint16_t));
1678 meta->setCountingPasses(false);
1679
1680 // Save out the data blocks of the grid.
1681 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1682 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1683 meta->setPass(pass);
1684 tree().writeBuffers(os, saveFloatAsHalf());
1685 }
1686 }
1687 }
1688
1689
1690 //static
1691 template<typename TreeT>
1692 inline bool
1693 Grid<TreeT>::hasMultiPassIO()
1694 {
1695 return HasMultiPassIO<Grid>::value;
1696 }
1697
1698
1699 template<typename TreeT>
1700 inline void
1701 Grid<TreeT>::print(std::ostream& os, int verboseLevel) const
1702 {
1703 tree().print(os, verboseLevel);
1704
1705 if (metaCount() > 0) {
1706 os << "Additional metadata:" << std::endl;
1707 for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1708 os << " " << it->first;
1709 if (it->second) {
1710 const std::string value = it->second->str();
1711 if (!value.empty()) os << ": " << value;
1712 }
1713 os << "\n";
1714 }
1715 }
1716
1717 os << "Transform:" << std::endl;
1718 transform().print(os, /*indent=*/" ");
1719 os << std::endl;
1720 }
1721
1722
1724
1725
1726 template<typename GridType>
1727 inline typename GridType::Ptr
1728 createGrid(const typename GridType::ValueType& background)
1729 {
1730 return GridType::create(background);
1731 }
1732
1733
1734 template<typename GridType>
1735 inline typename GridType::Ptr
1736 createGrid()
1737 {
1738 return GridType::create();
1739 }
1740
1741
1742 template<typename TreePtrType>
1743 inline typename Grid<typename TreePtrType::element_type>::Ptr
1744 createGrid(TreePtrType tree)
1745 {
1746 using TreeType = typename TreePtrType::element_type;
1747 return Grid<TreeType>::create(tree);
1748 }
1749
1750
1751 template<typename GridType>
1752 typename GridType::Ptr
1753 createLevelSet(Real voxelSize, Real halfWidth)
1754 {
1755 using ValueType = typename GridType::ValueType;
1756
1757 // GridType::ValueType is required to be a floating-point scalar.
1758 static_assert(std::is_floating_point<ValueType>::value,
1759 "level-set grids must be floating-point-valued");
1760
1761 typename GridType::Ptr grid = GridType::create(
1762 /*background=*/static_cast<ValueType>(voxelSize * halfWidth));
1763 grid->setTransform(math::Transform::createLinearTransform(voxelSize));
1764 grid->setGridClass(GRID_LEVEL_SET);
1765 return grid;
1766 }
1767
1768
1770
1771
1772 namespace internal {
1773
1775 template<typename OpT, typename GridBaseT, typename T, typename ...Ts>
1776 struct GridApplyImpl { static bool apply(GridBaseT&, OpT&) { return false; } };
1777
1778 // Partial specialization for (nonempty) TypeLists
1780 template<typename OpT, typename GridBaseT, typename GridT, typename ...GridTs>
1781 struct GridApplyImpl<OpT, GridBaseT, TypeList<GridT, GridTs...>>
1782 {
1783 static bool apply(GridBaseT& grid, OpT& op)
1784 {
1785 if (grid.template isType<GridT>()) {
1786 op(static_cast<typename CopyConstness<GridBaseT, GridT>::Type&>(grid));
1787 return true;
1788 }
1789 return GridApplyImpl<OpT, GridBaseT, TypeList<GridTs...>>::apply(grid, op);
1790 }
1791 };
1792
1793 } // namespace internal
1794
1795
1796 template<typename GridTypeListT, typename OpT>
1797 inline bool
1798 GridBase::apply(OpT& op) const
1799 {
1800 return internal::GridApplyImpl<OpT, const GridBase, GridTypeListT>::apply(*this, op);
1801 }
1802
1803 template<typename GridTypeListT, typename OpT>
1804 inline bool
1805 GridBase::apply(OpT& op)
1806 {
1807 return internal::GridApplyImpl<OpT, GridBase, GridTypeListT>::apply(*this, op);
1808 }
1809
1810 template<typename GridTypeListT, typename OpT>
1811 inline bool
1812 GridBase::apply(const OpT& op) const
1813 {
1814 return internal::GridApplyImpl<const OpT, const GridBase, GridTypeListT>::apply(*this, op);
1815 }
1816
1817 template<typename GridTypeListT, typename OpT>
1818 inline bool
1819 GridBase::apply(const OpT& op)
1820 {
1821 return internal::GridApplyImpl<const OpT, GridBase, GridTypeListT>::apply(*this, op);
1822 }
1823
1824 } // namespace OPENVDB_VERSION_NAME
1825 } // namespace openvdb
1826
1827 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::NonConstTreePtrType
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1130
openvdb::v7_0::Grid::clear
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:730
openvdb::v7_0::Grid::constTreePtr
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:897
openvdb::v7_0::TreeAdapter::constTree
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1088
openvdb::v7_0::GridBase::writeTransform
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:471
openvdb::v7_0::GridBase::GridBase
GridBase(GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:493
openvdb::v7_0::GridBase::transformPtr
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:402
openvdb::v7_0::Grid::empty
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:728
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
Definition: Platform.h:197
openvdb::v7_0::GridBase::createGrid
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
openvdb::v7_0::Grid::constBaseTreePtr
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:898
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::GridPtrType
typename GridType::Ptr GridPtrType
Definition: Grid.h:1133
openvdb::v7_0::GridCPtrSetPtr
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:527
openvdb::v7_0::Grid::writeTopology
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:1603
openvdb::v7_0::Grid::copyReplacingMetadataAndTransform
ConstPtr copyReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
Definition: Grid.h:1382
openvdb::v7_0::GridBase::META_GRID_CLASS
static const char *const META_GRID_CLASS
Definition: Grid.h:350
openvdb::v7_0::TreeAdapter::tree
static TreeType & tree(TreeType &t)
Definition: Grid.h:1082
openvdb::v7_0::VecType
VecType
Definition: Types.h:482
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::NonConstTreeType
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1098
openvdb::v7_0::Grid::TreeType
_TreeType TreeType
Definition: Grid.h:577
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::NonConstTreePtrType
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1101
openvdb::v7_0::GridBase::isRegistered
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
openvdb::v7_0::GridBase::copyGridWithNewTree
virtual GridBase::Ptr copyGridWithNewTree() const =0
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
openvdb::v7_0::TreeAdapter::constTree
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1089
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::NonConstAccessorType
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1139
openvdb::v7_0::Grid::readBuffers
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1611
openvdb::v7_0::math::BBox< Vec3d >
openvdb::v7_0::GridPtrSetCIter
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:521
openvdb::v7_0::Grid::valueType
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:717
openvdb::v7_0::Grid::readTopology
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:1595
openvdb::v7_0::math::Transform::Ptr
SharedPtr< Transform > Ptr
Definition: Transform.h:42
openvdb::v7_0::GridCPtrVecCIter
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:516
openvdb::v7_0::Grid::copyWithNewTree
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:1401
Types.h
openvdb::v7_0::TreeBase
tree::TreeBase TreeBase
Definition: Grid.h:26
openvdb::v7_0::GridPtrSet
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:519
openvdb::v7_0::Grid::isRegistered
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:967
openvdb::v7_0::GridBase::worldToIndex
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
Definition: Grid.h:440
openvdb::v7_0::GridCPtrSet
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:524
openvdb::v7_0::GridNamePred::operator()
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:534
openvdb::v7_0::GridBase::vecTypeDescription
static std::string vecTypeDescription(VecType)
Return a string describing how the given type of vector data is affected by transformations (e....
openvdb::v7_0::TreeAdapter::TreeType
_TreeType TreeType
Definition: Grid.h:1067
openvdb::v7_0::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
openvdb::v7_0::GridBase::saveFloatAsHalf
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
openvdb::v7_0::gridConstPtrCast
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:1024
openvdb::v7_0::GridBase::~GridBase
~GridBase() override
Definition: Grid.h:86
openvdb::v7_0::GridBase::constTransformPtr
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:403
openvdb::v7_0::Grid::clip
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1516
openvdb::v7_0::Grid::topologyDifference
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:1550
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::tree
static TreeType & tree(TreeType &t)
Definition: Grid.h:1141
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::ConstGridPtrType
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1135
openvdb::v7_0::GridBase::META_FILE_BBOX_MAX
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:357
openvdb::v7_0::GridBase::stringToVecType
static VecType stringToVecType(const std::string &)
openvdb::v7_0::GridBase::clearVectorType
void clearVectorType()
Remove the setting specifying the type of vector data stored in this grid.
openvdb::v7_0::GridBase::baseTree
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:182
openvdb::v7_0::TreeAdapter::GridPtrType
typename GridType::Ptr GridPtrType
Definition: Grid.h:1074
openvdb::v7_0::GridBase::transform
const math::Transform & transform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:411
openvdb::v7_0::GridBase::META_FILE_MEM_BYTES
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:359
openvdb::v7_0::GridBase::setTransform
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform.
Definition: Grid.h:1242
Transform.h
openvdb::v7_0::TreeAdapter::NonConstTreePtrType
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1071
openvdb::v7_0::GridBase::GridBase
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:481
openvdb::v7_0::Grid::copy
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:1393
openvdb::v7_0::GridBase::constTransform
const math::Transform & constTransform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:412
openvdb::v7_0::tree::ValueAccessor
Definition: ValueAccessor.h:194
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::NonConstGridPtrType
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1134
openvdb::v7_0::GridBase::writeTopology
virtual void writeTopology(std::ostream &) const =0
Write the grid topology to a stream. This will write only the grid structure, not the actual data buf...
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::NonConstGridPtrType
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1105
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::AccessorType
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1137
openvdb::v7_0::Grid::Ptr
SharedPtr< Grid > Ptr
Definition: Grid.h:574
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::NonConstAccessorType
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1110
openvdb::v7_0::GridBase::addStatsMetadata
void addStatsMetadata()
Add metadata to this grid comprising the current values of statistics like the active voxel count and...
openvdb::v7_0::GridPtrVecCIter
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:511
openvdb::v7_0::GridBase::clearGridClass
void clearGridClass()
Remove the setting specifying the class of this grid's volumetric data.
openvdb::v7_0::GridBase::setTree
virtual void setTree(TreeBase::Ptr)=0
Associate the given tree with this grid, in place of its existing tree.
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::constTree
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1119
openvdb::v7_0::GridCPtrVec
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:514
openvdb::v7_0::Grid::copyGridReplacingTransform
GridBase::ConstPtr copyGridReplacingTransform(math::Transform::Ptr xform) const override
Return a new grid of the same type as this grid whose tree is shared with this grid,...
Definition: Grid.h:1433
openvdb::v7_0::Grid::gridType
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:714
openvdb::v7_0::Grid::copyGrid
GridBase::Ptr copyGrid() override
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
Definition: Grid.h:1411
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::constTree
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1118
openvdb::v7_0::GridNamePred::name
Name name
Definition: Grid.h:535
openvdb::v7_0::Grid::sparseFill
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:1484
openvdb::v7_0::MergePolicy
MergePolicy
Definition: Types.h:505
openvdb::v7_0::Grid::pruneGrid
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1506
openvdb::v7_0::Grid::~Grid
~Grid() override
Definition: Grid.h:641
openvdb::v7_0::GridBase::META_SAVE_HALF_FLOAT
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:353
openvdb::v7_0::GridBase::deepCopyGrid
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::ValueType
typename TreeType::ValueType ValueType
Definition: Grid.h:1107
openvdb::v7_0::TreeAdapter::constTree
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1086
openvdb::v7_0::Grid::unregisterGrid
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:978
openvdb::v7_0::GridBase::META_VECTOR_TYPE
static const char *const META_VECTOR_TYPE
Definition: Grid.h:355
Name.h
openvdb::v7_0::SharedPtr
std::shared_ptr< T > SharedPtr
Definition: Types.h:91
openvdb::v7_0::Grid::UnsafeAccessor
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:592
openvdb::v7_0::Real
double Real
Definition: Types.h:37
openvdb::v7_0::GridBase::vecTypeExamples
static std::string vecTypeExamples(VecType)
openvdb::v7_0::GridBase::clipGrid
void clipGrid(const BBoxd &)
Clip this grid to the given world-space bounding box.
openvdb::v7_0::GridBase::evalActiveVoxelBoundingBox
virtual CoordBBox evalActiveVoxelBoundingBox() const =0
openvdb::v7_0::GridBase::type
virtual Name type() const =0
Return the name of this grid's type.
openvdb::v7_0::GridBase::readNonresidentBuffers
virtual void readNonresidentBuffers() const =0
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
openvdb::v7_0::Grid::ValueOffIter
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:585
openvdb::v7_0::GridBase::voxelSize
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:429
openvdb::v7_0::TreeAdapter::TreePtrType
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1069
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::tree
static TreeType & tree(GridType &g)
Definition: Grid.h:1142
openvdb::v7_0::GridBase::readBuffers
virtual void readBuffers(std::istream &, const CoordBBox &)=0
Read all of this grid's data buffers that intersect the given index-space bounding box.
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::NonConstTreeType
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1127
openvdb::v7_0::TreeAdapter::tree
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1084
openvdb::v7_0::GridBase::META_GRID_NAME
static const char *const META_GRID_NAME
Definition: Grid.h:352
openvdb::v7_0::GridBase::ConstPtr
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
openvdb::v7_0::Grid::copyGridWithNewTree
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:1449
openvdb::v7_0::Grid::readNonresidentBuffers
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:1656
openvdb::v7_0::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
openvdb::v7_0::GridBase::print
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const =0
Output a human-readable description of this grid.
openvdb::v7_0::GridBase::clearRegistry
static void clearRegistry()
Clear the grid type registry.
openvdb::v7_0::Grid::TreePtrType
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:578
openvdb::v7_0::GridBase::copyGrid
virtual GridBase::Ptr copyGrid()=0
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
openvdb::v7_0::math::Vec3d
Vec3< double > Vec3d
Definition: Vec3.h:662
MetaMap.h
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::ConstGridPtrType
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1106
openvdb::v7_0::GridBase::getStatsMetadata
MetaMap::Ptr getStatsMetadata() const
Return a new MetaMap containing just the metadata that was added to this grid with addStatsMetadata.
openvdb::v7_0::GridCPtrVecPtr
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:517
openvdb::v7_0::Grid::memUsage
Index64 memUsage() const override
Definition: Grid.h:884
openvdb::v7_0::TreeAdapter::ConstTreePtrType
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1070
openvdb::v7_0::Grid
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:28
openvdb::v7_0::Grid::registerGrid
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:969
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:230
openvdb::v7_0::GridBase::getVectorType
VecType getVectorType() const
Return the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this g...
openvdb::v7_0::Grid::getConstAccessor
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:747
openvdb::v7_0::MetaMap::Ptr
SharedPtr< MetaMap > Ptr
Definition: MetaMap.h:22
openvdb::v7_0::GridBase::Ptr
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
openvdb::v7_0::Grid::constTree
const TreeType & constTree() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:907
openvdb::v7_0::Grid::create
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1318
openvdb::v7_0::Grid::beginValueAll
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:770
openvdb::v7_0::GridBase::apply
bool apply(OpT &) const
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid.
Definition: Grid.h:1798
openvdb::v7_0::Grid::deepCopyGrid
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:706
openvdb::v7_0::GridBase::copyGridReplacingTransform
virtual GridBase::ConstPtr copyGridReplacingTransform(math::Transform::Ptr xform) const =0
Return a new grid of the same type as this grid whose tree is shared with this grid,...
openvdb::v7_0::TreeAdapter::ConstAccessorType
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1079
openvdb::v7_0::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:20
openvdb::v7_0::gridPtrCast
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:1008
openvdb::v7_0::GridBase::vecTypeToString
static std::string vecTypeToString(VecType)
Return the metadata string value for the given type of vector data.
openvdb::v7_0::Grid::getConstUnsafeAccessor
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:755
openvdb::v7_0::Grid::topologyIntersection
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:1541
openvdb::v7_0::GridBase::evalActiveVoxelDim
virtual Coord evalActiveVoxelDim() const =0
Return the dimensions of the axis-aligned bounding box of all active voxels.
openvdb::v7_0::io::getStreamMetadataPtr
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
openvdb::v7_0::Grid::evalActiveVoxelBoundingBox
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1569
openvdb::v7_0::GridBase::copyGrid
virtual GridBase::ConstPtr copyGrid() const =0
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
openvdb::v7_0::Grid::setTree
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1460
openvdb::v7_0::TreeAdapter::NonConstGridPtrType
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1075
openvdb::v7_0::Grid::ValueOnIter
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:583
openvdb::v7_0::GridBase::indexToWorld
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:438
openvdb::v7_0::LEVEL_SET_HALF_WIDTH
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:460
openvdb::v7_0::Grid::getUnsafeAccessor
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:743
openvdb::v7_0::GridBase::META_FILE_COMPRESSION
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:358
openvdb::v7_0::GridBase::setVectorType
void setVectorType(VecType)
Specify the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this ...
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::ConstAccessorType
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1109
openvdb::v7_0::TypeError
Definition: Exceptions.h:64
openvdb::v7_0::GridBase::constGrid
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Definition: Grid.h:1219
openvdb::v7_0::Grid::evalActiveVoxelDim
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1579
openvdb::v7_0::TreeAdapter::ValueType
typename TreeType::ValueType ValueType
Definition: Grid.h:1077
openvdb::v7_0::GridBase::baseTreePtr
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:173
openvdb::v7_0::Grid::cbeginValueOn
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:762
openvdb::v7_0::GridPtrSetPtr
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:522
openvdb::v7_0::GridBase::gridClassToString
static std::string gridClassToString(GridClass)
Return the metadata string value for the given class of volumetric data.
openvdb::v7_0::Grid::print
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1701
openvdb::v7_0::Grid::ValueOffCIter
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:586
openvdb::v7_0::GridBase::GridBase
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:490
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::tree
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1114
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::GridPtrType
typename GridType::Ptr GridPtrType
Definition: Grid.h:1104
openvdb::v7_0::Grid::beginValueOff
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:766
openvdb::v7_0::Grid::copyGridReplacingMetadataAndTransform
GridBase::ConstPtr copyGridReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const override
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
Definition: Grid.h:1440
openvdb::v7_0::Grid::beginValueOn
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:760
openvdb::v7_0::Grid::getAccessor
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:735
openvdb::v7_0::Grid::type
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:712
openvdb::v7_0::math::Transform::createLinearTransform
static Transform::Ptr createLinearTransform(double voxelSize=1.0)
Create and return a shared pointer to a new transform.
openvdb::v7_0::GridPtrVecIter
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:510
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::AccessorType
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1108
openvdb::v7_0::GridBase::memUsage
virtual Index64 memUsage() const =0
Return the number of bytes of memory used by this grid.
openvdb::v7_0::GridBase::empty
virtual bool empty() const =0
Return true if this grid contains only background voxels.
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::constTree
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1150
openvdb::v7_0::GridBase::META_FILE_VOXEL_COUNT
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:360
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
openvdb::v7_0::GridBase::indexToWorld
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:436
openvdb::v7_0::GridBase::META_FILE_BBOX_MIN
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:356
openvdb::v7_0::TreeAdapter::constTree
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1087
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::constTree
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1117
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::constTree
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1148
openvdb::v7_0::TreeAdapter
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1066
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::ConstTreePtrType
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1100
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::TreeType
_TreeType TreeType
Definition: Grid.h:1097
openvdb::v7_0::Grid::ValueAllCIter
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:588
openvdb::v7_0::GridBase::registerGrid
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
openvdb::v7_0::tree::TreeBase::ConstPtr
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:39
openvdb::v7_0::math::Transform::ConstPtr
SharedPtr< const Transform > ConstPtr
Definition: Transform.h:43
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::tree
static TreeType & tree(GridType &g)
Definition: Grid.h:1113
openvdb::v7_0::Grid::copyGridReplacingMetadata
GridBase::ConstPtr copyGridReplacingMetadata(const MetaMap &meta) const override
Return a new grid of the same type as this grid whose tree and transform is shared with this grid and...
Definition: Grid.h:1426
openvdb::v7_0::findGridByName
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:552
openvdb::v7_0::GridBase::isInWorldSpace
bool isInWorldSpace() const
openvdb::v7_0::GridBase::isType
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:148
openvdb::v7_0::GridBase::setSaveFloatAsHalf
void setSaveFloatAsHalf(bool)
Return this grid's user-specified name.
openvdb::v7_0::Grid::copyReplacingMetadata
ConstPtr copyReplacingMetadata(const MetaMap &meta) const
Return a new grid of the same type as this grid whose tree and transform is shared with this grid and...
Definition: Grid.h:1365
openvdb::v7_0::TreeAdapter::NonConstTreeType
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1068
openvdb::v7_0::GridBase::baseTreePtr
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:1235
openvdb::v7_0::GridBase::META_IS_LOCAL_SPACE
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:354
openvdb::v7_0::Grid::operator=
Grid & operator=(const Grid &)=delete
Disallow assignment, since it wouldn't be obvious whether the copy is deep or shallow.
Tree.h
openvdb::v7_0::Grid::ValueConverter
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:602
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::ConstAccessorType
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1138
openvdb::v7_0::Grid::beginValueAll
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:772
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::tree
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1146
openvdb::v7_0::Grid::writeBuffers
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1664
openvdb::v7_0::GridBase::getGridClass
GridClass getGridClass() const
Return the class of volumetric data (level set, fog volume, etc.) that is stored in this grid.
openvdb::v7_0::Grid::denseFill
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:1499
openvdb::v7_0::io::getFormatVersion
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::tree
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1115
openvdb::v7_0::GridBase::unregisterGrid
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
openvdb::v7_0::Grid::BuildType
typename _TreeType::BuildType BuildType
Definition: Grid.h:581
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::tree
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1144
openvdb::v7_0::Grid::activeVoxelCount
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:874
openvdb::v7_0::tools::clip
GridType::Ptr clip(const GridType &grid, const BBoxd &bbox, bool keepInterior=true)
Clip the given grid against a world-space bounding box and return a new grid containing the result.
Definition: Clip.h:348
openvdb::v7_0::GridBase::readTransform
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:469
openvdb::v7_0::GridBase::setName
void setName(const std::string &)
Specify a name for this grid.
openvdb::v7_0::Grid::treePtr
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:896
openvdb::v7_0::GridBase::META_GRID_CREATOR
static const char *const META_GRID_CREATOR
Definition: Grid.h:351
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
Bracket code with OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN/_END, to inhibit warnings about type conve...
Definition: Platform.h:196
openvdb::v7_0::Grid::tree
const TreeType & tree() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:906
openvdb::v7_0::Grid::evalMinMax
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1561
openvdb::v7_0::createGrid
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1744
openvdb::v7_0::Grid::Accessor
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:590
openvdb::v7_0::GridCPtrSetCIter
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:526
openvdb::v7_0::Grid::ValueOnCIter
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:584
logging.h
io.h
openvdb::v7_0::GridBase::constBaseTree
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:192
openvdb::v7_0::GridBase::grid
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:1197
openvdb::v7_0::GridBase::stringToGridClass
static GridClass stringToGridClass(const std::string &)
Return the class of volumetric data specified by the given string.
openvdb::v7_0::GridBase::setGridClass
void setGridClass(GridClass)
Specify the class of volumetric data (level set, fog volume, etc.) that is stored in this grid.
openvdb::v7_0::HasMultiPassIO
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1165
openvdb::v7_0::Name
std::string Name
Definition: Name.h:17
openvdb::v7_0::math::Transform
Definition: Transform.h:40
openvdb::v7_0::GridBase::copyGridReplacingMetadataAndTransform
virtual GridBase::ConstPtr copyGridReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const =0
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
openvdb::v7_0::CopyConstness::Type
typename std::remove_const< ToType >::type Type
Definition: Types.h:298
openvdb::v7_0::TypeList
A list of types (not necessarily unique)
Definition: Types.h:390
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::ValueType
typename TreeType::ValueType ValueType
Definition: Grid.h:1136
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::tree
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1143
openvdb::v7_0::GridBase::valueType
virtual Name valueType() const =0
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::constTree
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1149
openvdb::v7_0::GridBase::clip
virtual void clip(const CoordBBox &)=0
Clip this grid to the given index-space bounding box.
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::TreePtrType
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1099
openvdb::v7_0::GridBase
Abstract base class for typed grids.
Definition: Grid.h:78
openvdb::v7_0::GridPtrSetIter
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:520
openvdb::v7_0::deepCopyTypedGrid
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:1050
openvdb::v7_0::TreeAdapter::NonConstAccessorType
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1080
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::constTree
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1116
openvdb::v7_0::TreeAdapter< Grid< _TreeType > >::tree
static TreeType & tree(TreeType &t)
Definition: Grid.h:1112
openvdb::v7_0::Grid::topologyUnion
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:1532
openvdb::v7_0::GridBase::voxelSize
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:432
openvdb::v7_0::Grid::ConstAccessor
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:591
openvdb::v7_0::GridNamePred
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:532
openvdb::v7_0::GridPtrVec
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:509
openvdb::v7_0::GridBase::newTree
virtual void newTree()=0
Set a new tree with the same background value as the previous tree.
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::constTree
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1147
openvdb::v7_0::GridBase::readBuffers
virtual void readBuffers(std::istream &)=0
Read all data buffers for this grid.
openvdb::v7_0::GridBase::getName
std::string getName() const
Return this grid's user-specified name.
openvdb::v7_0::Grid::hasMultiPassIO
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers.
Definition: Grid.h:1693
openvdb::v7_0::StaticPtrCast
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:123
openvdb::v7_0::ValueError
Definition: Exceptions.h:65
openvdb::v7_0::Grid::Grid
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1253
openvdb::v7_0::tree::internal::LeafBufferFlags
Definition: LeafBuffer.h:41
openvdb::v7_0::GridBase::gridClassToMenuName
static std::string gridClassToMenuName(GridClass)
Return a formatted string version of the grid class.
openvdb::v7_0::TreeAdapter::ConstGridPtrType
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1076
openvdb::v7_0::GridClass
GridClass
Definition: Types.h:452
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::TreeType
_TreeType TreeType
Definition: Grid.h:1126
openvdb::v7_0::GRID_LEVEL_SET
@ GRID_LEVEL_SET
Definition: Types.h:454
openvdb::v7_0::tree::TreeBase::Ptr
SharedPtr< TreeBase > Ptr
Definition: Tree.h:38
openvdb::v7_0::GridCPtrVecIter
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:515
openvdb::v7_0::GridBase::pruneGrid
virtual void pruneGrid(float tolerance=0.0)=0
Reduce the memory footprint of this grid by increasing its sparseness either losslessly (tolerance = ...
openvdb::v7_0::TreeAdapter::tree
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1085
openvdb::v7_0::Grid::ValueAllIter
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:587
openvdb::v7_0::GridPtrVecPtr
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:512
openvdb
Definition: Exceptions.h:13
openvdb::v7_0::GridBase::hasUniformVoxels
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:434
openvdb::v7_0::Grid::ConstPtr
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:575
openvdb::v7_0::GridCPtrSetIter
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:525
openvdb::v7_0::Grid::merge
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1523
openvdb::v7_0::GridBase::clear
virtual void clear()=0
Empty this grid, setting all voxels to the background.
openvdb::v7_0::Grid::cbeginValueAll
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:774
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::tree
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1145
openvdb::v7_0::Index64
uint64_t Index64
Definition: Types.h:30
openvdb::v7_0::Grid::newTree
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1473
openvdb::v7_0::TreeAdapter::tree
static TreeType & tree(GridType &g)
Definition: Grid.h:1083
openvdb::v7_0::GridBase::META_FILE_DELAYED_LOAD
static const char *const META_FILE_DELAYED_LOAD
Definition: Grid.h:361
openvdb::v7_0::Grid::beginValueOn
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:758
openvdb::v7_0::OPENVDB_FILE_VERSION_MULTIPASS_IO
@ OPENVDB_FILE_VERSION_MULTIPASS_IO
Definition: version.h:198
openvdb::v7_0::io::StreamMetadata::Ptr
SharedPtr< StreamMetadata > Ptr
Definition: io.h:33
openvdb::v7_0::GridBase::constBaseTreePtr
virtual TreeBase::ConstPtr constBaseTreePtr() const =0
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
openvdb::v7_0::GridBase::baseTree
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:187
openvdb::v7_0::Grid::background
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:725
openvdb::v7_0::GridBase::activeVoxelCount
virtual Index64 activeVoxelCount() const =0
Return the number of active voxels.
openvdb::v7_0::MERGE_ACTIVE_STATES
@ MERGE_ACTIVE_STATES
Definition: Types.h:506
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::ConstTreePtrType
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1129
openvdb::v7_0::Grid::beginValueOff
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:764
openvdb::v7_0::GridBase::setCreator
void setCreator(const std::string &)
Provide a description of this grid's creator.
openvdb::v7_0::createGrid
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1728
openvdb::v7_0::GridBase::setIsInWorldSpace
void setIsInWorldSpace(bool)
Specify whether this grid's voxel values are in world space or in local space.
openvdb::v7_0::Grid::ConstTreePtrType
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:579
openvdb::v7_0::TreeAdapter::AccessorType
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1078
openvdb::v7_0::Grid::copyReplacingTransform
ConstPtr copyReplacingTransform(math::Transform::Ptr xform) const
Return a new grid of the same type as this grid whose tree is shared with this grid,...
Definition: Grid.h:1375
openvdb::v7_0::GridBase::getCreator
std::string getCreator() const
Return the user-specified description of this grid's creator.
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
openvdb::v7_0::ShallowCopy
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:678
openvdb::v7_0::Grid::deepCopy
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:704
openvdb::v7_0::GridBase::writeBuffers
virtual void writeBuffers(std::ostream &) const =0
Write out all data buffers for this grid.
openvdb::v7_0::Grid::fill
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:1492
Exceptions.h
openvdb::v7_0::Grid::tree
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:905
openvdb::v7_0::Grid::ValueType
typename _TreeType::ValueType ValueType
Definition: Grid.h:580
openvdb::v7_0::Grid::getAccessor
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:745
openvdb::v7_0::Grid::ConstUnsafeAccessor
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:593
openvdb::v7_0::TreeAdapter< tree::ValueAccessor< _TreeType > >::TreePtrType
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1128
openvdb::v7_0::GridBase::readTopology
virtual void readTopology(std::istream &)=0
Read the grid topology from a stream. This will read only the grid structure, not the actual data buf...
openvdb::v7_0::GridNamePred::GridNamePred
GridNamePred(const Name &_name)
Definition: Grid.h:533
openvdb::v7_0::tree::TreeBase
Base class for typed trees.
Definition: Tree.h:36
openvdb::v7_0::Grid::cbeginValueOff
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:768
OPENVDB_LOG_WARN
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253
openvdb::v7_0::GridBase::GridFactory
Ptr(*)() GridFactory
Definition: Grid.h:83
openvdb::v7_0::createLevelSet
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:1753