OpenVDB  6.2.1
Grid.h
Go to the documentation of this file.
1 //
3 // Copyright (c) DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 
31 #ifndef OPENVDB_GRID_HAS_BEEN_INCLUDED
32 #define OPENVDB_GRID_HAS_BEEN_INCLUDED
33 
34 #include "Exceptions.h"
35 #include "MetaMap.h"
36 #include "Types.h"
37 #include "io/io.h"
38 #include "math/Transform.h"
39 #include "tree/Tree.h"
40 #include "util/logging.h"
41 #include "util/Name.h"
42 #include <cassert>
43 #include <iostream>
44 #include <set>
45 #include <type_traits>
46 #include <vector>
47 
48 
49 namespace openvdb {
51 namespace OPENVDB_VERSION_NAME {
52 
54 
55 template<typename> class Grid; // forward declaration
56 
57 
62 template<typename GridType>
63 inline typename GridType::Ptr createGrid(const typename GridType::ValueType& background);
64 
65 
69 template<typename GridType>
70 inline typename GridType::Ptr createGrid();
71 
72 
77 template<typename TreePtrType>
79 
80 
95 template<typename GridType>
96 typename GridType::Ptr createLevelSet(
97  Real voxelSize = 1.0, Real halfWidth = LEVEL_SET_HALF_WIDTH);
98 
99 
101 
102 
105 {
106 public:
109 
110  using GridFactory = Ptr (*)();
111 
112 
113  ~GridBase() override {}
114 
115 
118 
119 #if OPENVDB_ABI_VERSION_NUMBER <= 3
120  OPENVDB_DEPRECATED virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const = 0;
124 #else
125  virtual GridBase::Ptr copyGrid() = 0;
130  virtual GridBase::ConstPtr copyGrid() const = 0;
133  virtual GridBase::Ptr copyGridWithNewTree() const = 0;
134 #endif
135  virtual GridBase::Ptr deepCopyGrid() const = 0;
137 
139 
140 
143 
145  static Ptr createGrid(const Name& type);
146 
148  static bool isRegistered(const Name &type);
149 
151  static void clearRegistry();
152 
154 
157 
159  virtual Name type() const = 0;
161  virtual Name valueType() const = 0;
162 
164  template<typename GridType>
165  bool isType() const { return (this->type() == GridType::gridType()); }
166 
168 
170  template<typename GridType>
173  static typename GridType::Ptr grid(const GridBase::Ptr&);
174  template<typename GridType>
175  static typename GridType::ConstPtr grid(const GridBase::ConstPtr&);
176  template<typename GridType>
177  static typename GridType::ConstPtr constGrid(const GridBase::Ptr&);
178  template<typename GridType>
179  static typename GridType::ConstPtr constGrid(const GridBase::ConstPtr&);
181 
184 
187  TreeBase::Ptr baseTreePtr();
190  TreeBase::ConstPtr baseTreePtr() const { return this->constBaseTreePtr(); }
193  virtual TreeBase::ConstPtr constBaseTreePtr() const = 0;
194 
199  TreeBase& baseTree() { return const_cast<TreeBase&>(this->constBaseTree()); }
204  const TreeBase& baseTree() const { return this->constBaseTree(); }
209  const TreeBase& constBaseTree() const { return *(this->constBaseTreePtr()); }
210 
217  virtual void setTree(TreeBase::Ptr) = 0;
218 
220  virtual void newTree() = 0;
221 
223 
225  virtual bool empty() const = 0;
227  virtual void clear() = 0;
228 
229 
232 
238  virtual void pruneGrid(float tolerance = 0.0) = 0;
239 
240 #if OPENVDB_ABI_VERSION_NUMBER >= 3
241  void clipGrid(const BBoxd&);
246 
251  virtual void clip(const CoordBBox&) = 0;
252 #endif
253 
255 
280  template<typename GridTypeListT, typename OpT> inline bool apply(OpT&) const;
281  template<typename GridTypeListT, typename OpT> inline bool apply(OpT&);
282  template<typename GridTypeListT, typename OpT> inline bool apply(const OpT&) const;
283  template<typename GridTypeListT, typename OpT> inline bool apply(const OpT&);
285 
288 
290  std::string getName() const;
292  void setName(const std::string&);
293 
295  std::string getCreator() const;
297  void setCreator(const std::string&);
298 
301  bool saveFloatAsHalf() const;
302  void setSaveFloatAsHalf(bool);
303 
307  GridClass getGridClass() const;
311  void setGridClass(GridClass);
313  void clearGridClass();
314 
316 
318  static std::string gridClassToString(GridClass);
320  static std::string gridClassToMenuName(GridClass);
325  static GridClass stringToGridClass(const std::string&);
326 
329 
333  VecType getVectorType() const;
337  void setVectorType(VecType);
339  void clearVectorType();
340 
342 
344  static std::string vecTypeToString(VecType);
347  static std::string vecTypeExamples(VecType);
350  static std::string vecTypeDescription(VecType);
351  static VecType stringToVecType(const std::string&);
352 
355 
359  bool isInWorldSpace() const;
361  void setIsInWorldSpace(bool);
362 
364 
365  // Standard metadata field names
366  // (These fields should normally not be accessed directly, but rather
367  // via the accessor methods above, when available.)
368  // Note: Visual C++ requires these declarations to be separate statements.
369  static const char* const META_GRID_CLASS;
370  static const char* const META_GRID_CREATOR;
371  static const char* const META_GRID_NAME;
372  static const char* const META_SAVE_HALF_FLOAT;
373  static const char* const META_IS_LOCAL_SPACE;
374  static const char* const META_VECTOR_TYPE;
375  static const char* const META_FILE_BBOX_MIN;
376  static const char* const META_FILE_BBOX_MAX;
377  static const char* const META_FILE_COMPRESSION;
378  static const char* const META_FILE_MEM_BYTES;
379  static const char* const META_FILE_VOXEL_COUNT;
380  static const char* const META_FILE_DELAYED_LOAD;
381 
382 
385 
387  virtual Index64 activeVoxelCount() const = 0;
388 
391  virtual CoordBBox evalActiveVoxelBoundingBox() const = 0;
392 
394  virtual Coord evalActiveVoxelDim() const = 0;
395 
397  virtual Index64 memUsage() const = 0;
398 
403  void addStatsMetadata();
409  MetaMap::Ptr getStatsMetadata() const;
410 
412 
413 
416 
418  math::Transform::Ptr transformPtr() { return mTransform; }
421  math::Transform::ConstPtr transformPtr() const { return mTransform; }
422  math::Transform::ConstPtr constTransformPtr() const { return mTransform; }
424 
425  math::Transform& transform() { return *mTransform; }
430  const math::Transform& transform() const { return *mTransform; }
431  const math::Transform& constTransform() const { return *mTransform; }
433 
435 
438 
445  void setTransform(math::Transform::Ptr);
446 
448  Vec3d voxelSize() const { return transform().voxelSize(); }
451  Vec3d voxelSize(const Vec3d& xyz) const { return transform().voxelSize(xyz); }
453  bool hasUniformVoxels() const { return mTransform->hasUniformScale(); }
455  Vec3d indexToWorld(const Vec3d& xyz) const { return transform().indexToWorld(xyz); }
457  Vec3d indexToWorld(const Coord& ijk) const { return transform().indexToWorld(ijk); }
459  Vec3d worldToIndex(const Vec3d& xyz) const { return transform().worldToIndex(xyz); }
460 
462 
463 
466 
469  virtual void readTopology(std::istream&) = 0;
472  virtual void writeTopology(std::ostream&) const = 0;
473 
475  virtual void readBuffers(std::istream&) = 0;
476 #if OPENVDB_ABI_VERSION_NUMBER >= 3
477  virtual void readBuffers(std::istream&, const CoordBBox&) = 0;
484  virtual void readNonresidentBuffers() const = 0;
485 #endif
486  virtual void writeBuffers(std::ostream&) const = 0;
488 
490  void readTransform(std::istream& is) { transform().read(is); }
492  void writeTransform(std::ostream& os) const { transform().write(os); }
493 
495  virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const = 0;
496 
498 
499 
500 protected:
502  GridBase(): mTransform(math::Transform::createLinearTransform()) {}
503 
505  GridBase(const GridBase& other): MetaMap(other), mTransform(other.mTransform->copy()) {}
506 
507 #if OPENVDB_ABI_VERSION_NUMBER <= 3
511  GridBase(const GridBase& other, ShallowCopy): MetaMap(other), mTransform(other.mTransform) {}
512 #else
513  GridBase(GridBase& other, ShallowCopy): MetaMap(other), mTransform(other.mTransform) {}
515 #endif
516 
518  static void registerGrid(const Name& type, GridFactory);
520  static void unregisterGrid(const Name& type);
521 
522 
523 private:
524  math::Transform::Ptr mTransform;
525 }; // class GridBase
526 
527 
529 
530 
531 using GridPtrVec = std::vector<GridBase::Ptr>;
532 using GridPtrVecIter = GridPtrVec::iterator;
533 using GridPtrVecCIter = GridPtrVec::const_iterator;
535 
536 using GridCPtrVec = std::vector<GridBase::ConstPtr>;
537 using GridCPtrVecIter = GridCPtrVec::iterator;
538 using GridCPtrVecCIter = GridCPtrVec::const_iterator;
540 
541 using GridPtrSet = std::set<GridBase::Ptr>;
542 using GridPtrSetIter = GridPtrSet::iterator;
543 using GridPtrSetCIter = GridPtrSet::const_iterator;
545 
546 using GridCPtrSet = std::set<GridBase::ConstPtr>;
547 using GridCPtrSetIter = GridCPtrSet::iterator;
548 using GridCPtrSetCIter = GridCPtrSet::const_iterator;
550 
551 
554 {
555  GridNamePred(const Name& _name): name(_name) {}
556  bool operator()(const GridBase::ConstPtr& g) const { return g && g->getName() == name; }
558 };
559 
561 template<typename GridPtrContainerT>
562 inline typename GridPtrContainerT::value_type
563 findGridByName(const GridPtrContainerT& container, const Name& name)
564 {
565  using GridPtrT = typename GridPtrContainerT::value_type;
566  typename GridPtrContainerT::const_iterator it =
567  std::find_if(container.begin(), container.end(), GridNamePred(name));
568  return (it == container.end() ? GridPtrT() : *it);
569 }
570 
572 template<typename KeyT, typename GridPtrT>
573 inline GridPtrT
574 findGridByName(const std::map<KeyT, GridPtrT>& container, const Name& name)
575 {
576  using GridPtrMapT = std::map<KeyT, GridPtrT>;
577  for (typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
578  it != end; ++it)
579  {
580  const GridPtrT& grid = it->second;
581  if (grid && grid->getName() == name) return grid;
582  }
583  return GridPtrT();
584 }
586 
587 
589 
590 
592 template<typename _TreeType>
593 class Grid: public GridBase
594 {
595 public:
598 
599  using TreeType = _TreeType;
600  using TreePtrType = typename _TreeType::Ptr;
601  using ConstTreePtrType = typename _TreeType::ConstPtr;
602  using ValueType = typename _TreeType::ValueType;
603  using BuildType = typename _TreeType::BuildType;
604 
605  using ValueOnIter = typename _TreeType::ValueOnIter;
606  using ValueOnCIter = typename _TreeType::ValueOnCIter;
607  using ValueOffIter = typename _TreeType::ValueOffIter;
608  using ValueOffCIter = typename _TreeType::ValueOffCIter;
609  using ValueAllIter = typename _TreeType::ValueAllIter;
610  using ValueAllCIter = typename _TreeType::ValueAllCIter;
611 
616 
623  template<typename OtherValueType>
624  struct ValueConverter {
626  };
627 
629  static Ptr create(const ValueType& background);
631  static Ptr create();
634  static Ptr create(TreePtrType);
637  static Ptr create(const GridBase& other);
638 
639 
641  Grid();
643  explicit Grid(const ValueType& background);
647  explicit Grid(TreePtrType);
649  Grid(const Grid&);
655  template<typename OtherTreeType>
656  explicit Grid(const Grid<OtherTreeType>&);
657 #if OPENVDB_ABI_VERSION_NUMBER <= 3
661 #else
662  Grid(Grid&, ShallowCopy);
664 #endif
665  explicit Grid(const GridBase&);
668 
669  ~Grid() override {}
670 
672  Grid& operator=(const Grid&) = delete;
673 
674 
675 #if OPENVDB_ABI_VERSION_NUMBER <= 3
676 
677  OPENVDB_DEPRECATED Ptr copy(CopyPolicy treePolicy = CP_SHARE) const;
685  OPENVDB_DEPRECATED GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const override;
687 #else
688 
693  Ptr copy();
696  ConstPtr copy() const;
699  Ptr copyWithNewTree() const;
700 
703  GridBase::Ptr copyGrid() override;
706  GridBase::ConstPtr copyGrid() const override;
709  GridBase::Ptr copyGridWithNewTree() const override;
711 #endif
712 
716  Ptr deepCopy() const { return Ptr(new Grid(*this)); }
718  GridBase::Ptr deepCopyGrid() const override { return this->deepCopy(); }
719 
721 
722 
724  Name type() const override { return this->gridType(); }
726  static Name gridType() { return TreeType::treeType(); }
727 
729  Name valueType() const override { return tree().valueType(); }
730 
731 
734 
737  const ValueType& background() const { return mTree->background(); }
738 
740  bool empty() const override { return tree().empty(); }
742  void clear() override { tree().clear(); }
743 
747  Accessor getAccessor() { return Accessor(tree()); }
757  ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
759  ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
768 
770  ValueOnIter beginValueOn() { return tree().beginValueOn(); }
772  ValueOnCIter beginValueOn() const { return tree().cbeginValueOn(); }
774  ValueOnCIter cbeginValueOn() const { return tree().cbeginValueOn(); }
776  ValueOffIter beginValueOff() { return tree().beginValueOff(); }
778  ValueOffCIter beginValueOff() const { return tree().cbeginValueOff(); }
780  ValueOffCIter cbeginValueOff() const { return tree().cbeginValueOff(); }
782  ValueAllIter beginValueAll() { return tree().beginValueAll(); }
784  ValueAllCIter beginValueAll() const { return tree().cbeginValueAll(); }
786  ValueAllCIter cbeginValueAll() const { return tree().cbeginValueAll(); }
787 
789 
792 
801  void sparseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
810  void fill(const CoordBBox& bbox, const ValueType& value, bool active = true);
811 
818  void denseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
819 
821  void pruneGrid(float tolerance = 0.0) override;
822 
823 #if OPENVDB_ABI_VERSION_NUMBER >= 3
824  void clip(const CoordBBox&) override;
829 #endif
830 
836  void merge(Grid& other, MergePolicy policy = MERGE_ACTIVE_STATES);
837 
851  template<typename OtherTreeType>
852  void topologyUnion(const Grid<OtherTreeType>& other);
853 
866  template<typename OtherTreeType>
867  void topologyIntersection(const Grid<OtherTreeType>& other);
868 
879  template<typename OtherTreeType>
880  void topologyDifference(const Grid<OtherTreeType>& other);
881 
883 
886 
888  Index64 activeVoxelCount() const override { return tree().activeVoxelCount(); }
890  CoordBBox evalActiveVoxelBoundingBox() const override;
892  Coord evalActiveVoxelDim() const override;
894  void evalMinMax(ValueType& minVal, ValueType& maxVal) const;
895 
898  Index64 memUsage() const override { return tree().memUsage(); }
899 
901 
902 
905 
907  TreePtrType treePtr() { return mTree; }
910  ConstTreePtrType treePtr() const { return mTree; }
911  ConstTreePtrType constTreePtr() const { return mTree; }
912  TreeBase::ConstPtr constBaseTreePtr() const override { return mTree; }
914 
915  TreeType& tree() { return *mTree; }
920  const TreeType& tree() const { return *mTree; }
921  const TreeType& constTree() const { return *mTree; }
923 
925 
928 
934  void setTree(TreeBase::Ptr) override;
935 
938  void newTree() override;
939 
941 
942 
945 
948  void readTopology(std::istream&) override;
951  void writeTopology(std::ostream&) const override;
952 
954  void readBuffers(std::istream&) override;
955 #if OPENVDB_ABI_VERSION_NUMBER >= 3
956  void readBuffers(std::istream&, const CoordBBox&) override;
963  void readNonresidentBuffers() const override;
964 #endif
965  void writeBuffers(std::ostream&) const override;
967 
969  void print(std::ostream& = std::cout, int verboseLevel = 1) const override;
970 
972 
976  static inline bool hasMultiPassIO();
977 
978 
981 
985  static void registerGrid()
986  {
987  GridBase::registerGrid(Grid::gridType(), Grid::factory);
989  OPENVDB_LOG_WARN("delayed loading of grids of type " << Grid::gridType()
990  << " might not be threadsafe on this platform");
991  }
992  }
995 
997 
998 
999 private:
1001  static GridBase::Ptr factory() { return Grid::create(); }
1002 
1003  TreePtrType mTree;
1004 }; // class Grid
1005 
1006 
1008 
1009 
1017 template<typename GridType>
1018 inline typename GridType::Ptr
1020 {
1021  return GridBase::grid<GridType>(grid);
1022 }
1023 
1024 
1033 template<typename GridType>
1034 inline typename GridType::ConstPtr
1036 {
1037  return GridBase::constGrid<GridType>(grid);
1038 }
1039 
1040 
1042 
1043 
1050 template<typename GridType>
1051 inline typename GridType::Ptr
1053 {
1054  if (!grid || !grid->isType<GridType>()) return typename GridType::Ptr();
1055  return gridPtrCast<GridType>(grid->deepCopyGrid());
1056 }
1057 
1058 
1059 template<typename GridType>
1060 inline typename GridType::Ptr
1062 {
1063  if (!grid.isType<GridType>()) return typename GridType::Ptr();
1064  return gridPtrCast<GridType>(grid.deepCopyGrid());
1065 }
1067 
1068 
1070 
1071 
1073 template<typename _TreeType>
1077 {
1078  using TreeType = _TreeType;
1079  using NonConstTreeType = typename std::remove_const<TreeType>::type;
1080  using TreePtrType = typename TreeType::Ptr;
1081  using ConstTreePtrType = typename TreeType::ConstPtr;
1082  using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1085  using GridPtrType = typename GridType::Ptr;
1088  using ValueType = typename TreeType::ValueType;
1092 
1093  static TreeType& tree(TreeType& t) { return t; }
1094  static TreeType& tree(GridType& g) { return g.tree(); }
1095  static const TreeType& tree(const TreeType& t) { return t; }
1096  static const TreeType& tree(const GridType& g) { return g.tree(); }
1097  static const TreeType& constTree(TreeType& t) { return t; }
1098  static const TreeType& constTree(GridType& g) { return g.constTree(); }
1099  static const TreeType& constTree(const TreeType& t) { return t; }
1100  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1101 };
1102 
1103 
1105 template<typename _TreeType>
1106 struct TreeAdapter<Grid<_TreeType> >
1107 {
1108  using TreeType = _TreeType;
1109  using NonConstTreeType = typename std::remove_const<TreeType>::type;
1110  using TreePtrType = typename TreeType::Ptr;
1111  using ConstTreePtrType = typename TreeType::ConstPtr;
1112  using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1115  using GridPtrType = typename GridType::Ptr;
1118  using ValueType = typename TreeType::ValueType;
1122 
1123  static TreeType& tree(TreeType& t) { return t; }
1124  static TreeType& tree(GridType& g) { return g.tree(); }
1125  static const TreeType& tree(const TreeType& t) { return t; }
1126  static const TreeType& tree(const GridType& g) { return g.tree(); }
1127  static const TreeType& constTree(TreeType& t) { return t; }
1128  static const TreeType& constTree(GridType& g) { return g.constTree(); }
1129  static const TreeType& constTree(const TreeType& t) { return t; }
1130  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1131 };
1132 
1134 template<typename _TreeType>
1135 struct TreeAdapter<tree::ValueAccessor<_TreeType> >
1136 {
1137  using TreeType = _TreeType;
1138  using NonConstTreeType = typename std::remove_const<TreeType>::type;
1139  using TreePtrType = typename TreeType::Ptr;
1140  using ConstTreePtrType = typename TreeType::ConstPtr;
1141  using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1144  using GridPtrType = typename GridType::Ptr;
1147  using ValueType = typename TreeType::ValueType;
1151 
1152  static TreeType& tree(TreeType& t) { return t; }
1153  static TreeType& tree(GridType& g) { return g.tree(); }
1154  static TreeType& tree(AccessorType& a) { return a.tree(); }
1155  static const TreeType& tree(const TreeType& t) { return t; }
1156  static const TreeType& tree(const GridType& g) { return g.tree(); }
1157  static const TreeType& tree(const AccessorType& a) { return a.tree(); }
1158  static const TreeType& constTree(TreeType& t) { return t; }
1159  static const TreeType& constTree(GridType& g) { return g.constTree(); }
1160  static const TreeType& constTree(const TreeType& t) { return t; }
1161  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1162 };
1163 
1165 
1166 
1168 
1169 
1175 template<typename LeafNodeType>
1177  static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1178 };
1179 
1180 // Partial specialization for Tree types
1181 template<typename RootNodeType>
1182 struct HasMultiPassIO<tree::Tree<RootNodeType>> {
1183  // A tree is multi-pass if its (root node's) leaf node type is multi-pass.
1185 };
1186 
1187 // Partial specialization for Grid types
1188 template<typename TreeType>
1189 struct HasMultiPassIO<Grid<TreeType>> {
1190  // A grid is multi-pass if its tree's leaf node type is multi-pass.
1192 };
1193 
1194 
1196 
1197 
1198 template<typename GridType>
1199 inline typename GridType::Ptr
1201 {
1202  // The string comparison on type names is slower than a dynamic pointer cast, but
1203  // it is safer when pointers cross DSO boundaries, as they do in many Houdini nodes.
1204  if (grid && grid->type() == GridType::gridType()) {
1205  return StaticPtrCast<GridType>(grid);
1206  }
1207  return typename GridType::Ptr();
1208 }
1209 
1210 
1211 template<typename GridType>
1212 inline typename GridType::ConstPtr
1214 {
1215  return ConstPtrCast<const GridType>(
1216  GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1217 }
1218 
1219 
1220 template<typename GridType>
1221 inline typename GridType::ConstPtr
1223 {
1224  return ConstPtrCast<const GridType>(GridBase::grid<GridType>(grid));
1225 }
1226 
1227 
1228 template<typename GridType>
1229 inline typename GridType::ConstPtr
1231 {
1232  return ConstPtrCast<const GridType>(
1233  GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1234 }
1235 
1236 
1237 inline TreeBase::Ptr
1239 {
1240  return ConstPtrCast<TreeBase>(this->constBaseTreePtr());
1241 }
1242 
1243 
1244 inline void
1246 {
1247  if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
1248  mTransform = xform;
1249 }
1250 
1251 
1253 
1254 
1255 template<typename TreeT>
1256 inline Grid<TreeT>::Grid(): mTree(new TreeType)
1257 {
1258 }
1259 
1260 
1261 template<typename TreeT>
1262 inline Grid<TreeT>::Grid(const ValueType &background): mTree(new TreeType(background))
1263 {
1264 }
1265 
1266 
1267 template<typename TreeT>
1268 inline Grid<TreeT>::Grid(TreePtrType tree): mTree(tree)
1269 {
1270  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1271 }
1272 
1273 
1274 template<typename TreeT>
1275 inline Grid<TreeT>::Grid(const Grid& other):
1276  GridBase(other),
1277  mTree(StaticPtrCast<TreeType>(other.mTree->copy()))
1278 {
1279 }
1280 
1281 
1282 template<typename TreeT>
1283 template<typename OtherTreeType>
1285  GridBase(other),
1286  mTree(new TreeType(other.constTree()))
1287 {
1288 }
1289 
1290 
1291 #if OPENVDB_ABI_VERSION_NUMBER <= 3
1292 template<typename TreeT>
1293 inline Grid<TreeT>::Grid(const Grid& other, ShallowCopy):
1294  GridBase(other, ShallowCopy()),
1295  mTree(other.mTree)
1296 {
1297 }
1298 #else
1299 template<typename TreeT>
1301  GridBase(other),
1302  mTree(other.mTree)
1303 {
1304 }
1305 #endif
1306 
1307 
1308 template<typename TreeT>
1309 inline Grid<TreeT>::Grid(const GridBase& other):
1310  GridBase(other),
1311  mTree(new TreeType)
1312 {
1313 }
1314 
1315 
1316 //static
1317 template<typename TreeT>
1318 inline typename Grid<TreeT>::Ptr
1320 {
1321  return Grid::create(zeroVal<ValueType>());
1322 }
1323 
1324 
1325 //static
1326 template<typename TreeT>
1327 inline typename Grid<TreeT>::Ptr
1329 {
1330  return Ptr(new Grid(background));
1331 }
1332 
1333 
1334 //static
1335 template<typename TreeT>
1336 inline typename Grid<TreeT>::Ptr
1338 {
1339  return Ptr(new Grid(tree));
1340 }
1341 
1342 
1343 //static
1344 template<typename TreeT>
1345 inline typename Grid<TreeT>::Ptr
1347 {
1348  return Ptr(new Grid(other));
1349 }
1350 
1351 
1353 
1354 
1355 #if OPENVDB_ABI_VERSION_NUMBER <= 3
1356 
1357 template<typename TreeT>
1358 inline typename Grid<TreeT>::Ptr
1359 Grid<TreeT>::copy(CopyPolicy treePolicy) const
1360 {
1361  Ptr ret;
1362  switch (treePolicy) {
1363  case CP_NEW:
1364  ret.reset(new Grid(*this, ShallowCopy()));
1365  ret->newTree();
1366  break;
1367  case CP_COPY:
1368  ret.reset(new Grid(*this));
1369  break;
1370  case CP_SHARE:
1371  ret.reset(new Grid(*this, ShallowCopy()));
1372  break;
1373  }
1374  return ret;
1375 }
1376 
1377 
1378 template<typename TreeT>
1379 inline GridBase::Ptr
1380 Grid<TreeT>::copyGrid(CopyPolicy treePolicy) const
1381 {
1382  return this->copy(treePolicy);
1383 }
1384 
1385 #else // if OPENVDB_ABI_VERSION_NUMBER > 3
1386 
1387 template<typename TreeT>
1388 inline typename Grid<TreeT>::ConstPtr
1390 {
1391  return ConstPtr{new Grid{*const_cast<Grid*>(this), ShallowCopy{}}};
1392 }
1393 
1394 template<typename TreeT>
1395 inline typename Grid<TreeT>::Ptr
1397 {
1398  return Ptr{new Grid{*this, ShallowCopy{}}};
1399 }
1400 
1401 
1402 template<typename TreeT>
1403 inline typename Grid<TreeT>::Ptr
1405 {
1406  Ptr result{new Grid{*const_cast<Grid*>(this), ShallowCopy{}}};
1407  result->newTree();
1408  return result;
1409 }
1410 
1411 
1412 template<typename TreeT>
1413 inline GridBase::Ptr
1415 {
1416  return this->copy();
1417 }
1418 
1419 template<typename TreeT>
1420 inline GridBase::ConstPtr
1422 {
1423  return this->copy();
1424 }
1425 
1426 
1427 template<typename TreeT>
1428 inline GridBase::Ptr
1430 {
1431  return this->copyWithNewTree();
1432 }
1433 
1434 #endif
1435 
1436 
1438 
1439 
1440 template<typename TreeT>
1441 inline void
1443 {
1444  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1445  if (tree->type() != TreeType::treeType()) {
1446  OPENVDB_THROW(TypeError, "Cannot assign a tree of type "
1447  + tree->type() + " to a grid of type " + this->type());
1448  }
1449  mTree = StaticPtrCast<TreeType>(tree);
1450 }
1451 
1452 
1453 template<typename TreeT>
1454 inline void
1456 {
1457  mTree.reset(new TreeType(this->background()));
1458 }
1459 
1460 
1462 
1463 
1464 template<typename TreeT>
1465 inline void
1466 Grid<TreeT>::sparseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1467 {
1468  tree().sparseFill(bbox, value, active);
1469 }
1470 
1471 
1472 template<typename TreeT>
1473 inline void
1474 Grid<TreeT>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1475 {
1476  this->sparseFill(bbox, value, active);
1477 }
1478 
1479 template<typename TreeT>
1480 inline void
1481 Grid<TreeT>::denseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1482 {
1483  tree().denseFill(bbox, value, active);
1484 }
1485 
1486 template<typename TreeT>
1487 inline void
1488 Grid<TreeT>::pruneGrid(float tolerance)
1489 {
1491  const auto value = zeroVal<ValueType>() + tolerance;
1493  this->tree().prune(static_cast<ValueType>(value));
1494 }
1495 
1496 #if OPENVDB_ABI_VERSION_NUMBER >= 3
1497 template<typename TreeT>
1498 inline void
1499 Grid<TreeT>::clip(const CoordBBox& bbox)
1500 {
1501  tree().clip(bbox);
1502 }
1503 #endif
1504 
1505 
1506 template<typename TreeT>
1507 inline void
1509 {
1510  tree().merge(other.tree(), policy);
1511 }
1512 
1513 
1514 template<typename TreeT>
1515 template<typename OtherTreeType>
1516 inline void
1518 {
1519  tree().topologyUnion(other.tree());
1520 }
1521 
1522 
1523 template<typename TreeT>
1524 template<typename OtherTreeType>
1525 inline void
1527 {
1528  tree().topologyIntersection(other.tree());
1529 }
1530 
1531 
1532 template<typename TreeT>
1533 template<typename OtherTreeType>
1534 inline void
1536 {
1537  tree().topologyDifference(other.tree());
1538 }
1539 
1540 
1542 
1543 
1544 template<typename TreeT>
1545 inline void
1547 {
1548  tree().evalMinMax(minVal, maxVal);
1549 }
1550 
1551 
1552 template<typename TreeT>
1553 inline CoordBBox
1555 {
1556  CoordBBox bbox;
1557  tree().evalActiveVoxelBoundingBox(bbox);
1558  return bbox;
1559 }
1560 
1561 
1562 template<typename TreeT>
1563 inline Coord
1565 {
1566  Coord dim;
1567  const bool nonempty = tree().evalActiveVoxelDim(dim);
1568  return (nonempty ? dim : Coord());
1569 }
1570 
1571 
1573 
1574 
1577 
1578 template<typename TreeT>
1579 inline void
1580 Grid<TreeT>::readTopology(std::istream& is)
1581 {
1582  tree().readTopology(is, saveFloatAsHalf());
1583 }
1584 
1585 
1586 template<typename TreeT>
1587 inline void
1588 Grid<TreeT>::writeTopology(std::ostream& os) const
1589 {
1590  tree().writeTopology(os, saveFloatAsHalf());
1591 }
1592 
1593 
1594 template<typename TreeT>
1595 inline void
1596 Grid<TreeT>::readBuffers(std::istream& is)
1597 {
1599  tree().readBuffers(is, saveFloatAsHalf());
1600  } else {
1601  uint16_t numPasses = 1;
1602  is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
1604  assert(bool(meta));
1605  for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1606  uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1607  meta->setPass(pass);
1608  tree().readBuffers(is, saveFloatAsHalf());
1609  }
1610  }
1611 }
1612 
1613 
1614 #if OPENVDB_ABI_VERSION_NUMBER >= 3
1615 
1618 template<typename TreeT>
1619 inline void
1620 Grid<TreeT>::readBuffers(std::istream& is, const CoordBBox& bbox)
1621 {
1623  tree().readBuffers(is, bbox, saveFloatAsHalf());
1624  } else {
1625  uint16_t numPasses = 1;
1626  is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
1628  assert(bool(meta));
1629  for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1630  uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1631  meta->setPass(pass);
1632  tree().readBuffers(is, saveFloatAsHalf());
1633  }
1634  // Cannot clip inside readBuffers() when using multiple passes,
1635  // so instead clip afterwards.
1636  tree().clip(bbox);
1637  }
1638 }
1639 
1640 
1641 template<typename TreeT>
1642 inline void
1644 {
1645  tree().readNonresidentBuffers();
1646 }
1647 
1648 #endif
1649 
1650 
1651 template<typename TreeT>
1652 inline void
1653 Grid<TreeT>::writeBuffers(std::ostream& os) const
1654 {
1655  if (!hasMultiPassIO()) {
1656  tree().writeBuffers(os, saveFloatAsHalf());
1657  } else {
1658  // Determine how many leaf buffer passes are required for this grid
1660  assert(bool(meta));
1661  uint16_t numPasses = 1;
1662  meta->setCountingPasses(true);
1663  meta->setPass(0);
1664  tree().writeBuffers(os, saveFloatAsHalf());
1665  numPasses = static_cast<uint16_t>(meta->pass());
1666  os.write(reinterpret_cast<const char*>(&numPasses), sizeof(uint16_t));
1667  meta->setCountingPasses(false);
1668 
1669  // Save out the data blocks of the grid.
1670  for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1671  uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1672  meta->setPass(pass);
1673  tree().writeBuffers(os, saveFloatAsHalf());
1674  }
1675  }
1676 }
1677 
1678 
1679 //static
1680 template<typename TreeT>
1681 inline bool
1683 {
1685 }
1686 
1687 
1688 template<typename TreeT>
1689 inline void
1690 Grid<TreeT>::print(std::ostream& os, int verboseLevel) const
1691 {
1692  tree().print(os, verboseLevel);
1693 
1694  if (metaCount() > 0) {
1695  os << "Additional metadata:" << std::endl;
1696  for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1697  os << " " << it->first;
1698  if (it->second) {
1699  const std::string value = it->second->str();
1700  if (!value.empty()) os << ": " << value;
1701  }
1702  os << "\n";
1703  }
1704  }
1705 
1706  os << "Transform:" << std::endl;
1707  transform().print(os, /*indent=*/" ");
1708  os << std::endl;
1709 }
1710 
1711 
1713 
1714 
1715 template<typename GridType>
1716 inline typename GridType::Ptr
1717 createGrid(const typename GridType::ValueType& background)
1718 {
1719  return GridType::create(background);
1720 }
1721 
1722 
1723 template<typename GridType>
1724 inline typename GridType::Ptr
1726 {
1727  return GridType::create();
1728 }
1729 
1730 
1731 template<typename TreePtrType>
1734 {
1735  using TreeType = typename TreePtrType::element_type;
1736  return Grid<TreeType>::create(tree);
1737 }
1738 
1739 
1740 template<typename GridType>
1741 typename GridType::Ptr
1743 {
1744  using ValueType = typename GridType::ValueType;
1745 
1746  // GridType::ValueType is required to be a floating-point scalar.
1747  static_assert(std::is_floating_point<ValueType>::value,
1748  "level-set grids must be floating-point-valued");
1749 
1750  typename GridType::Ptr grid = GridType::create(
1751  /*background=*/static_cast<ValueType>(voxelSize * halfWidth));
1752  grid->setTransform(math::Transform::createLinearTransform(voxelSize));
1753  grid->setGridClass(GRID_LEVEL_SET);
1754  return grid;
1755 }
1756 
1757 
1759 
1760 
1761 namespace internal {
1762 
1764 template<typename OpT, typename GridBaseT, typename T, typename ...Ts>
1765 struct GridApplyImpl { static bool apply(GridBaseT&, OpT&) { return false; } };
1766 
1767 // Partial specialization for (nonempty) TypeLists
1769 template<typename OpT, typename GridBaseT, typename GridT, typename ...GridTs>
1770 struct GridApplyImpl<OpT, GridBaseT, TypeList<GridT, GridTs...>>
1771 {
1772  static bool apply(GridBaseT& grid, OpT& op)
1773  {
1774  if (grid.template isType<GridT>()) {
1775  op(static_cast<typename CopyConstness<GridBaseT, GridT>::Type&>(grid));
1776  return true;
1777  }
1778  return GridApplyImpl<OpT, GridBaseT, TypeList<GridTs...>>::apply(grid, op);
1779  }
1780 };
1781 
1782 } // namespace internal
1783 
1784 
1785 template<typename GridTypeListT, typename OpT>
1786 inline bool
1787 GridBase::apply(OpT& op) const
1788 {
1789  return internal::GridApplyImpl<OpT, const GridBase, GridTypeListT>::apply(*this, op);
1790 }
1791 
1792 template<typename GridTypeListT, typename OpT>
1793 inline bool
1795 {
1796  return internal::GridApplyImpl<OpT, GridBase, GridTypeListT>::apply(*this, op);
1797 }
1798 
1799 template<typename GridTypeListT, typename OpT>
1800 inline bool
1801 GridBase::apply(const OpT& op) const
1802 {
1803  return internal::GridApplyImpl<const OpT, const GridBase, GridTypeListT>::apply(*this, op);
1804 }
1805 
1806 template<typename GridTypeListT, typename OpT>
1807 inline bool
1808 GridBase::apply(const OpT& op)
1809 {
1810  return internal::GridApplyImpl<const OpT, GridBase, GridTypeListT>::apply(*this, op);
1811 }
1812 
1813 } // namespace OPENVDB_VERSION_NAME
1814 } // namespace openvdb
1815 
1816 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
1817 
1818 // Copyright (c) DreamWorks Animation LLC
1819 // All rights reserved. This software is distributed under the
1820 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1081
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid&#39;s voxel at position (x, y, z).
Definition: Grid.h:451
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:378
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1161
#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:223
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid&#39;s.
Definition: Grid.h:718
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1128
typename GridType::Ptr GridPtrType
Definition: Grid.h:1115
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 ...
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:742
SharedPtr< Transform > Ptr
Definition: Transform.h:69
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:288
typename TreeType::ValueType ValueType
Definition: Grid.h:1147
_TreeType TreeType
Definition: Grid.h:599
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1096
TreeType & tree()
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:919
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid&#39;s voxels.
Definition: Grid.h:759
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:376
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1442
void topologyIntersection(const Grid< OtherTreeType > &other)
Intersect this grid&#39;s set of active values with the active values of the other grid, whose value type may be different.
Definition: Grid.h:1526
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1119
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1155
ValueAllIter beginValueAll()
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:782
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:539
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:502
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1125
#define OPENVDB_DEPRECATED
Definition: Platform.h:69
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1091
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1455
static const char *const META_FILE_DELAYED_LOAD
Definition: Grid.h:380
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid&#39;s voxels.
Definition: Grid.h:747
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1160
const TreeBase & constBaseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:209
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:165
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:534
void topologyDifference(const Grid< OtherTreeType > &other)
Difference this grid&#39;s set of active values with the active values of the other grid, whose value type may be different.
Definition: Grid.h:1535
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:1787
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< const _TreeType, true > ConstAccessor
Definition: Grid.h:613
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:597
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1097
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:774
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1157
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:492
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:372
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
Definition: Grid.h:1682
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:533
TreeBase::ConstPtr baseTreePtr() const
Return a pointer to this grid&#39;s tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:190
TreeBase::Ptr baseTreePtr()
Return a pointer to this grid&#39;s tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:1238
static TreeType & tree(GridType &g)
Definition: Grid.h:1094
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:601
static TreeType & tree(GridType &g)
Definition: Grid.h:1153
SharedPtr< const Transform > ConstPtr
Definition: Transform.h:70
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid&#39;s voxels.
Definition: Grid.h:757
GridNamePred(const Name &_name)
Definition: Grid.h:555
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:546
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1117
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:548
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:532
static TreeType & tree(TreeType &t)
Definition: Grid.h:1152
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:612
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1508
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1129
typename _TreeType::ValueType ValueType
Definition: Grid.h:602
static const char *const META_GRID_NAME
Definition: Grid.h:371
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1145
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:1580
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1121
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1158
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:510
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1141
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:780
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1120
~GridBase() override
Definition: Grid.h:113
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1546
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1095
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:375
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:1429
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:778
typename _TreeType::BuildType BuildType
Definition: Grid.h:603
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid&#39;s transform to the given coordinates.
Definition: Grid.h:457
ValueOffIter beginValueOff()
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:776
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:373
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1100
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:747
SharedPtr< MetaMap > Ptr
Definition: MetaMap.h:49
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46
const math::Transform & constTransform() const
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:431
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:537
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
SharedPtr< T > StaticPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that points to the same object as the given pointer after a static_cast...
Definition: Types.h:171
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:600
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:1035
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
Definition: Platform.h:224
_TreeType TreeType
Definition: Grid.h:1078
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:985
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:556
void readNonresidentBuffers() const override
Read all of this grid&#39;s data buffers that are not yet resident in memory (because delayed loading is ...
Definition: Grid.h:1643
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
MetaIterator endMeta()
Definition: MetaMap.h:112
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:422
Vec3< double > Vec3d
Definition: Vec3.h:689
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:543
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:531
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:1481
Name name
Definition: Grid.h:557
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1690
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1080
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:541
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:786
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:726
double Real
Definition: Types.h:67
MergePolicy
Definition: Types.h:555
Definition: Types.h:556
GridBase(const GridBase &other)
Deep copy another grid&#39;s metadata and transform.
Definition: Grid.h:505
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1089
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:544
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:888
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1653
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1090
const TreeType & tree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:920
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1112
openvdb::GridBase Grid
Definition: Utils.h:60
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:615
typename std::remove_const< ToType >::type Type
Definition: Types.h:348
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1082
SharedPtr< StreamMetadata > Ptr
Definition: io.h:60
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:128
typename GridType::Ptr GridPtrType
Definition: Grid.h:1144
Definition: Exceptions.h:91
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1130
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
std::string Name
Definition: Name.h:44
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:379
math::Transform & transform()
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:429
GridType::Ptr deepCopyTypedGrid(const GridBase &grid)
Return a pointer to a deep copy of the given grid, provided that the grid&#39;s concrete type is GridType...
Definition: Grid.h:1061
static const char *const META_GRID_CLASS
Definition: Grid.h:369
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1596
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:1146
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1111
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:542
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid&#39;s voxels.
Definition: Grid.h:767
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid&#39;s transform to the given coordinates.
Definition: Grid.h:455
typename GridType::Ptr GridPtrType
Definition: Grid.h:1085
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:983
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1126
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1148
typename TreeType::ValueType ValueType
Definition: Grid.h:1118
tree::TreeBase TreeBase
Definition: Grid.h:53
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid&#39;s voxels...
Definition: Grid.h:755
static const char *const META_VECTOR_TYPE
Definition: Grid.h:374
void topologyUnion(const Grid< OtherTreeType > &other)
Union this grid&#39;s set of active values with the active values of the other grid, whose value type may...
Definition: Grid.h:1517
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:607
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1098
MetadataMap::const_iterator ConstMetaIterator
Definition: MetaMap.h:55
Index64 memUsage() const override
Definition: Grid.h:898
Definition: Exceptions.h:40
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:610
void print(std::ostream &os=std::cout, const std::string &indent="") const
Print a description of this transform.
GridClass
Definition: Types.h:502
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1127
static TreeType & tree(TreeType &t)
Definition: Grid.h:1093
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid&#39;s.
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1079
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:377
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1109
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:574
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:490
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:606
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:994
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:1404
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:624
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1156
VecType
Definition: Types.h:532
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:553
uint64_t Index64
Definition: Types.h:60
Abstract base class for typed grids.
Definition: Grid.h:104
TreeBase & baseTree()
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:199
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1140
Definition: Types.h:504
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1099
static TreeType & tree(GridType &g)
Definition: Grid.h:1124
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1087
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1499
SharedPtr< Grid > Ptr
Definition: Grid.h:596
Vec3d voxelSize() const
Return the size of this grid&#39;s voxels.
Definition: Grid.h:448
Base class for typed trees.
Definition: Tree.h:62
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:547
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1116
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid&#39;s transform to the given coordinates.
Definition: Grid.h:459
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:1200
Name type() const override
Return the name of this grid&#39;s type.
Definition: Grid.h:724
const TreeType & constTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:921
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid&#39;s.
Definition: Grid.h:716
_TreeType TreeType
Definition: Grid.h:1108
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1554
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1564
static Transform::Ptr createLinearTransform(double voxelSize=1.0)
Create and return a shared pointer to a new transform.
const math::Transform & transform() const
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:430
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:1588
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:1742
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:1466
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:1222
static TreeType & tree(TreeType &t)
Definition: Grid.h:1123
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:379
Definition: ValueAccessor.h:220
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1154
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:608
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
Definition: Transform.h:66
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form &#39;someVar << "some text" << ...&#39;.
Definition: logging.h:280
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1256
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1319
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1245
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1149
typename TreeType::ValueType ValueType
Definition: Grid.h:1088
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:784
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1138
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:536
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1159
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:549
Definition: Exceptions.h:92
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:1019
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1488
SharedPtr< TreeBase > Ptr
Definition: Tree.h:65
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1076
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180
ConstTreePtrType constTreePtr() const
Return a pointer to this grid&#39;s tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:911
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:66
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:1474
~Grid() override
Definition: Grid.h:669
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1110
GridBase::Ptr copyGrid() override
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid&#39;s and whos...
Definition: Grid.h:1414
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1150
MetaIterator beginMeta()
Definition: MetaMap.h:111
Name valueType() const override
Return the name of the type of a voxel&#39;s value (e.g., "float" or "vec3d").
Definition: Grid.h:729
size_t metaCount() const
Definition: MetaMap.h:118
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:538
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:614
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:1396
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1176
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:421
ConstTreePtrType treePtr() const
Return a pointer to this grid&#39;s tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:910
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1086
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:609
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1139
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:772
ValueOnIter beginValueOn()
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:770
const TreeBase & baseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:204
static const char *const META_GRID_CREATOR
Definition: Grid.h:370
const ValueType & background() const
Return this grid&#39;s background value.
Definition: Grid.h:737
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1733
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:108
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:605
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:740
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:453
TreeBase::ConstPtr constBaseTreePtr() const override
Return a pointer to this grid&#39;s tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:912