OpenVDB  4.0.1
Grid.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2017 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/Name.h"
41 #include <cassert>
42 #include <iostream>
43 #include <set>
44 #include <type_traits>
45 #include <vector>
46 
47 
48 namespace openvdb {
50 namespace OPENVDB_VERSION_NAME {
51 
53 
54 template<typename> class Grid; // forward declaration
55 
56 
61 template<typename GridType>
62 inline typename GridType::Ptr createGrid(const typename GridType::ValueType& background);
63 
64 
68 template<typename GridType>
69 inline typename GridType::Ptr createGrid();
70 
71 
76 template<typename TreePtrType>
78 
79 
94 template<typename GridType>
95 typename GridType::Ptr createLevelSet(
96  Real voxelSize = 1.0, Real halfWidth = LEVEL_SET_HALF_WIDTH);
97 
98 
100 
101 
104 {
105 public:
108 
109  using GridFactory = Ptr (*)();
110 
111 
112  ~GridBase() override {}
113 
114 #ifdef OPENVDB_3_ABI_COMPATIBLE
115  virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const = 0;
118 #else
119 
120  virtual GridBase::Ptr copyGrid() = 0;
123  virtual GridBase::ConstPtr copyGrid() const = 0;
125  virtual GridBase::Ptr copyGridWithNewTree() const = 0;
128 #endif
129  virtual GridBase::Ptr deepCopyGrid() const = 0;
131 
132 
133  //
134  // Registry methods
135  //
137  static Ptr createGrid(const Name& type);
138 
140  static bool isRegistered(const Name &type);
141 
143  static void clearRegistry();
144 
145 
146  //
147  // Grid type methods
148  //
150  virtual Name type() const = 0;
152  virtual Name valueType() const = 0;
153 
155  template<typename GridType>
156  bool isType() const { return (this->type() == GridType::gridType()); }
157 
159  template<typename GridType>
162  static typename GridType::Ptr grid(const GridBase::Ptr&);
163  template<typename GridType>
164  static typename GridType::ConstPtr grid(const GridBase::ConstPtr&);
165  template<typename GridType>
166  static typename GridType::ConstPtr constGrid(const GridBase::Ptr&);
167  template<typename GridType>
168  static typename GridType::ConstPtr constGrid(const GridBase::ConstPtr&);
170 
172  TreeBase::Ptr baseTreePtr();
175  TreeBase::ConstPtr baseTreePtr() const { return this->constBaseTreePtr(); }
176  virtual TreeBase::ConstPtr constBaseTreePtr() const = 0;
178 
180  TreeBase& baseTree() { return const_cast<TreeBase&>(this->constBaseTree()); }
185  const TreeBase& baseTree() const { return this->constBaseTree(); }
186  const TreeBase& constBaseTree() const { return *(this->constBaseTreePtr()); }
188 
194  virtual void setTree(TreeBase::Ptr) = 0;
195 
197  virtual void newTree() = 0;
198 
200  virtual bool empty() const = 0;
202  virtual void clear() = 0;
203 
209  virtual void pruneGrid(float tolerance = 0.0) = 0;
210 
211 #ifndef OPENVDB_2_ABI_COMPATIBLE
212  void clipGrid(const BBoxd&);
217 
222  virtual void clip(const CoordBBox&) = 0;
223 #endif
224 
225 
226  //
227  // Metadata
228  //
230  std::string getName() const;
232  void setName(const std::string&);
233 
235  std::string getCreator() const;
237  void setCreator(const std::string&);
238 
241  bool saveFloatAsHalf() const;
242  void setSaveFloatAsHalf(bool);
243 
245  GridClass getGridClass() const;
247  void setGridClass(GridClass);
249  void clearGridClass();
250 
252  static std::string gridClassToString(GridClass);
254  static std::string gridClassToMenuName(GridClass);
258  static GridClass stringToGridClass(const std::string&);
259 
262  VecType getVectorType() const;
265  void setVectorType(VecType);
267  void clearVectorType();
268 
270  static std::string vecTypeToString(VecType);
273  static std::string vecTypeExamples(VecType);
276  static std::string vecTypeDescription(VecType);
277  static VecType stringToVecType(const std::string&);
278 
282  bool isInWorldSpace() const;
284  void setIsInWorldSpace(bool);
285 
286  // Standard metadata field names
287  // (These fields should normally not be accessed directly, but rather
288  // via the accessor methods above, when available.)
289  // Note: Visual C++ requires these declarations to be separate statements.
290  static const char* const META_GRID_CLASS;
291  static const char* const META_GRID_CREATOR;
292  static const char* const META_GRID_NAME;
293  static const char* const META_SAVE_HALF_FLOAT;
294  static const char* const META_IS_LOCAL_SPACE;
295  static const char* const META_VECTOR_TYPE;
296  static const char* const META_FILE_BBOX_MIN;
297  static const char* const META_FILE_BBOX_MAX;
298  static const char* const META_FILE_COMPRESSION;
299  static const char* const META_FILE_MEM_BYTES;
300  static const char* const META_FILE_VOXEL_COUNT;
301 
302 
303  //
304  // Statistics
305  //
307  virtual Index64 activeVoxelCount() const = 0;
308 
311  virtual CoordBBox evalActiveVoxelBoundingBox() const = 0;
312 
314  virtual Coord evalActiveVoxelDim() const = 0;
315 
317  virtual Index64 memUsage() const = 0;
318 
323  void addStatsMetadata();
328  MetaMap::Ptr getStatsMetadata() const;
329 
330 
331  //
332  // Transform methods
333  //
335  math::Transform::Ptr transformPtr() { return mTransform; }
338  math::Transform::ConstPtr transformPtr() const { return mTransform; }
339  math::Transform::ConstPtr constTransformPtr() const { return mTransform; }
341 
342  math::Transform& transform() { return *mTransform; }
347  const math::Transform& transform() const { return *mTransform; }
348  const math::Transform& constTransform() const { return *mTransform; }
350  void setTransform(math::Transform::Ptr);
356 
358  Vec3d voxelSize() const { return transform().voxelSize(); }
361  Vec3d voxelSize(const Vec3d& xyz) const { return transform().voxelSize(xyz); }
363  bool hasUniformVoxels() const { return mTransform->hasUniformScale(); }
365  Vec3d indexToWorld(const Vec3d& xyz) const { return transform().indexToWorld(xyz); }
367  Vec3d indexToWorld(const Coord& ijk) const { return transform().indexToWorld(ijk); }
369  Vec3d worldToIndex(const Vec3d& xyz) const { return transform().worldToIndex(xyz); }
371 
372 
373  //
374  // I/O methods
375  //
378  virtual void readTopology(std::istream&) = 0;
381  virtual void writeTopology(std::ostream&) const = 0;
382 
384  virtual void readBuffers(std::istream&) = 0;
385 #ifndef OPENVDB_2_ABI_COMPATIBLE
386  virtual void readBuffers(std::istream&, const CoordBBox&) = 0;
393  virtual void readNonresidentBuffers() const = 0;
394 #endif
395  virtual void writeBuffers(std::ostream&) const = 0;
397 
399  void readTransform(std::istream& is) { transform().read(is); }
401  void writeTransform(std::ostream& os) const { transform().write(os); }
402 
404  virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const = 0;
405 
406 
407 protected:
409  GridBase(): mTransform(math::Transform::createLinearTransform()) {}
410 
412  GridBase(const GridBase& other): MetaMap(other), mTransform(other.mTransform->copy()) {}
413 
414 #ifdef OPENVDB_3_ABI_COMPATIBLE
415  GridBase(const GridBase& other, ShallowCopy): MetaMap(other), mTransform(other.mTransform) {}
417 #else
418  GridBase(GridBase& other, ShallowCopy): MetaMap(other), mTransform(other.mTransform) {}
420 #endif
421 
423  static void registerGrid(const Name& type, GridFactory);
425  static void unregisterGrid(const Name& type);
426 
427 
428 private:
429  math::Transform::Ptr mTransform;
430 }; // class GridBase
431 
432 
434 
435 
436 using GridPtrVec = std::vector<GridBase::Ptr>;
437 using GridPtrVecIter = GridPtrVec::iterator;
438 using GridPtrVecCIter = GridPtrVec::const_iterator;
440 
441 using GridCPtrVec = std::vector<GridBase::ConstPtr>;
442 using GridCPtrVecIter = GridCPtrVec::iterator;
443 using GridCPtrVecCIter = GridCPtrVec::const_iterator;
445 
446 using GridPtrSet = std::set<GridBase::Ptr>;
447 using GridPtrSetIter = GridPtrSet::iterator;
448 using GridPtrSetCIter = GridPtrSet::const_iterator;
450 
451 using GridCPtrSet = std::set<GridBase::ConstPtr>;
452 using GridCPtrSetIter = GridCPtrSet::iterator;
453 using GridCPtrSetCIter = GridCPtrSet::const_iterator;
455 
456 
459 {
460  GridNamePred(const Name& _name): name(_name) {}
461  bool operator()(const GridBase::ConstPtr& g) const { return g && g->getName() == name; }
463 };
464 
466 template<typename GridPtrContainerT>
467 inline typename GridPtrContainerT::value_type
468 findGridByName(const GridPtrContainerT& container, const Name& name)
469 {
470  using GridPtrT = typename GridPtrContainerT::value_type;
471  typename GridPtrContainerT::const_iterator it =
472  std::find_if(container.begin(), container.end(), GridNamePred(name));
473  return (it == container.end() ? GridPtrT() : *it);
474 }
475 
477 template<typename KeyT, typename GridPtrT>
478 inline GridPtrT
479 findGridByName(const std::map<KeyT, GridPtrT>& container, const Name& name)
480 {
481  using GridPtrMapT = std::map<KeyT, GridPtrT>;
482  for (typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
483  it != end; ++it)
484  {
485  const GridPtrT& grid = it->second;
486  if (grid && grid->getName() == name) return grid;
487  }
488  return GridPtrT();
489 }
491 
492 
494 
495 
497 template<typename _TreeType>
498 class Grid: public GridBase
499 {
500 public:
503 
504  using TreeType = _TreeType;
505  using TreePtrType = typename _TreeType::Ptr;
506  using ConstTreePtrType = typename _TreeType::ConstPtr;
507  using ValueType = typename _TreeType::ValueType;
508  using BuildType = typename _TreeType::BuildType;
509 
510  using ValueOnIter = typename _TreeType::ValueOnIter;
511  using ValueOnCIter = typename _TreeType::ValueOnCIter;
512  using ValueOffIter = typename _TreeType::ValueOffIter;
513  using ValueOffCIter = typename _TreeType::ValueOffCIter;
514  using ValueAllIter = typename _TreeType::ValueAllIter;
515  using ValueAllCIter = typename _TreeType::ValueAllCIter;
516 
521 
528  template<typename OtherValueType>
529  struct ValueConverter {
531  };
532 
534  static Ptr create(const ValueType& background);
536  static Ptr create();
539  static Ptr create(TreePtrType);
542  static Ptr create(const GridBase& other);
543 
544 
546  Grid();
548  explicit Grid(const ValueType& background);
552  explicit Grid(TreePtrType);
554  Grid(const Grid&);
560  template<typename OtherTreeType>
561  explicit Grid(const Grid<OtherTreeType>&);
562 #ifdef OPENVDB_3_ABI_COMPATIBLE
563  Grid(const Grid&, ShallowCopy);
565 #else
566  Grid(Grid&, ShallowCopy);
568 #endif
569  explicit Grid(const GridBase&);
572 
573  ~Grid() override {}
574 
576  Grid& operator=(const Grid&) = delete;
577 
578 
579 #ifdef OPENVDB_3_ABI_COMPATIBLE
580 
581  Ptr copy(CopyPolicy treePolicy = CP_SHARE) const;
587  GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const override;
589 #else
590 
591  Ptr copy();
594  ConstPtr copy() const;
596  Ptr copyWithNewTree() const;
599 
600  GridBase::Ptr copyGrid() override;
601  GridBase::ConstPtr copyGrid() const override;
602  GridBase::Ptr copyGridWithNewTree() const override;
603 #endif
604 
605  Ptr deepCopy() const { return Ptr(new Grid(*this)); }
607  GridBase::Ptr deepCopyGrid() const override { return this->deepCopy(); }
609 
611  Name type() const override { return this->gridType(); }
613  static Name gridType() { return TreeType::treeType(); }
614 
615 
616  //
617  // Voxel access methods
618  //
620  Name valueType() const override { return tree().valueType(); }
621 
625  const ValueType& background() const { return mTree->background(); }
626 
628  bool empty() const override { return tree().empty(); }
630  void clear() override { tree().clear(); }
631 
635  Accessor getAccessor() { return Accessor(tree()); }
646  ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
648  ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
650  ConstUnsafeAccessor getConstUnsafeAccessor() const { return ConstUnsafeAccessor(tree()); }
659 
661  ValueOnIter beginValueOn() { return tree().beginValueOn(); }
663  ValueOnCIter beginValueOn() const { return tree().cbeginValueOn(); }
664  ValueOnCIter cbeginValueOn() const { return tree().cbeginValueOn(); }
666 
667  ValueOffIter beginValueOff() { return tree().beginValueOff(); }
669  ValueOffCIter beginValueOff() const { return tree().cbeginValueOff(); }
670  ValueOffCIter cbeginValueOff() const { return tree().cbeginValueOff(); }
672 
673  ValueAllIter beginValueAll() { return tree().beginValueAll(); }
675  ValueAllCIter beginValueAll() const { return tree().cbeginValueAll(); }
676  ValueAllCIter cbeginValueAll() const { return tree().cbeginValueAll(); }
678 
680  void evalMinMax(ValueType& minVal, ValueType& maxVal) const;
681 
683  void sparseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
692  void fill(const CoordBBox& bbox, const ValueType& value, bool active = true);
694 
701  void denseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
702 
704  void pruneGrid(float tolerance = 0.0) override;
705 
706 #ifndef OPENVDB_2_ABI_COMPATIBLE
707  void clip(const CoordBBox&) override;
712 #endif
713 
719  void merge(Grid& other, MergePolicy policy = MERGE_ACTIVE_STATES);
720 
734  template<typename OtherTreeType>
735  void topologyUnion(const Grid<OtherTreeType>& other);
736 
749  template<typename OtherTreeType>
750  void topologyIntersection(const Grid<OtherTreeType>& other);
751 
762  template<typename OtherTreeType>
763  void topologyDifference(const Grid<OtherTreeType>& other);
764 
765  //
766  // Statistics
767  //
769  Index64 activeVoxelCount() const override { return tree().activeVoxelCount(); }
771  CoordBBox evalActiveVoxelBoundingBox() const override;
773  Coord evalActiveVoxelDim() const override;
774 
777  Index64 memUsage() const override { return tree().memUsage(); }
778 
779 
780  //
781  // Tree methods
782  //
784  TreePtrType treePtr() { return mTree; }
787  ConstTreePtrType treePtr() const { return mTree; }
788  ConstTreePtrType constTreePtr() const { return mTree; }
789  TreeBase::ConstPtr constBaseTreePtr() const override { return mTree; }
791 
792  TreeType& tree() { return *mTree; }
797  const TreeType& tree() const { return *mTree; }
798  const TreeType& constTree() const { return *mTree; }
800 
806  void setTree(TreeBase::Ptr) override;
807 
810  void newTree() override;
811 
812 
813  //
814  // I/O methods
815  //
818  void readTopology(std::istream&) override;
821  void writeTopology(std::ostream&) const override;
822 
824  void readBuffers(std::istream&) override;
825 #ifndef OPENVDB_2_ABI_COMPATIBLE
826  void readBuffers(std::istream&, const CoordBBox&) override;
833  void readNonresidentBuffers() const override;
834 #endif
835  void writeBuffers(std::ostream&) const override;
837 
839  void print(std::ostream& = std::cout, int verboseLevel = 1) const override;
840 
844  static inline bool hasMultiPassIO();
845 
846 
847  //
848  // Registry methods
849  //
853  static void registerGrid() { GridBase::registerGrid(Grid::gridType(), Grid::factory); }
856 
857 
858 private:
860  static GridBase::Ptr factory() { return Grid::create(); }
861 
862  TreePtrType mTree;
863 }; // class Grid
864 
865 
867 
868 
876 template<typename GridType>
877 inline typename GridType::Ptr
879 {
880  return GridBase::grid<GridType>(grid);
881 }
882 
883 
892 template<typename GridType>
893 inline typename GridType::ConstPtr
895 {
896  return GridBase::constGrid<GridType>(grid);
897 }
898 
899 
901 
902 
909 template<typename GridType>
910 inline typename GridType::Ptr
912 {
913  if (!grid || !grid->isType<GridType>()) return typename GridType::Ptr();
914  return gridPtrCast<GridType>(grid->deepCopyGrid());
915 }
916 
917 
918 template<typename GridType>
919 inline typename GridType::Ptr
921 {
922  if (!grid.isType<GridType>()) return typename GridType::Ptr();
923  return gridPtrCast<GridType>(grid.deepCopyGrid());
924 }
926 
927 
929 
930 
932 template<typename _TreeType>
936 {
937  using TreeType = _TreeType;
938  using NonConstTreeType = typename std::remove_const<TreeType>::type;
939  using TreePtrType = typename TreeType::Ptr;
940  using ConstTreePtrType = typename TreeType::ConstPtr;
941  using NonConstTreePtrType = typename NonConstTreeType::Ptr;
944  using GridPtrType = typename GridType::Ptr;
947  using ValueType = typename TreeType::ValueType;
951 
952  static TreeType& tree(TreeType& t) { return t; }
953  static TreeType& tree(GridType& g) { return g.tree(); }
954  static const TreeType& tree(const TreeType& t) { return t; }
955  static const TreeType& tree(const GridType& g) { return g.tree(); }
956  static const TreeType& constTree(TreeType& t) { return t; }
957  static const TreeType& constTree(GridType& g) { return g.constTree(); }
958  static const TreeType& constTree(const TreeType& t) { return t; }
959  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
960 };
961 
962 
964 template<typename _TreeType>
965 struct TreeAdapter<Grid<_TreeType> >
966 {
967  using TreeType = _TreeType;
968  using NonConstTreeType = typename std::remove_const<TreeType>::type;
969  using TreePtrType = typename TreeType::Ptr;
970  using ConstTreePtrType = typename TreeType::ConstPtr;
971  using NonConstTreePtrType = typename NonConstTreeType::Ptr;
974  using GridPtrType = typename GridType::Ptr;
977  using ValueType = typename TreeType::ValueType;
981 
982  static TreeType& tree(TreeType& t) { return t; }
983  static TreeType& tree(GridType& g) { return g.tree(); }
984  static const TreeType& tree(const TreeType& t) { return t; }
985  static const TreeType& tree(const GridType& g) { return g.tree(); }
986  static const TreeType& constTree(TreeType& t) { return t; }
987  static const TreeType& constTree(GridType& g) { return g.constTree(); }
988  static const TreeType& constTree(const TreeType& t) { return t; }
989  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
990 };
991 
993 template<typename _TreeType>
994 struct TreeAdapter<tree::ValueAccessor<_TreeType> >
995 {
996  using TreeType = _TreeType;
997  using NonConstTreeType = typename std::remove_const<TreeType>::type;
998  using TreePtrType = typename TreeType::Ptr;
999  using ConstTreePtrType = typename TreeType::ConstPtr;
1000  using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1003  using GridPtrType = typename GridType::Ptr;
1006  using ValueType = typename TreeType::ValueType;
1010 
1011  static TreeType& tree(TreeType& t) { return t; }
1012  static TreeType& tree(GridType& g) { return g.tree(); }
1013  static TreeType& tree(AccessorType& a) { return a.tree(); }
1014  static const TreeType& tree(const TreeType& t) { return t; }
1015  static const TreeType& tree(const GridType& g) { return g.tree(); }
1016  static const TreeType& tree(const AccessorType& a) { return a.tree(); }
1017  static const TreeType& constTree(TreeType& t) { return t; }
1018  static const TreeType& constTree(GridType& g) { return g.constTree(); }
1019  static const TreeType& constTree(const TreeType& t) { return t; }
1020  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1021 };
1022 
1024 
1025 
1027 
1028 
1034 template<typename LeafNodeType>
1036  static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1037 };
1038 
1039 // Partial specialization for Tree types
1040 template<typename RootNodeType>
1041 struct HasMultiPassIO<tree::Tree<RootNodeType>> {
1042  // A tree is multi-pass if its (root node's) leaf node type is multi-pass.
1044 };
1045 
1046 // Partial specialization for Grid types
1047 template<typename TreeType>
1048 struct HasMultiPassIO<Grid<TreeType>> {
1049  // A grid is multi-pass if its tree's leaf node type is multi-pass.
1051 };
1052 
1053 
1055 
1056 
1057 template<typename GridType>
1058 inline typename GridType::Ptr
1060 {
1061  // The string comparison on type names is slower than a dynamic pointer cast, but
1062  // it is safer when pointers cross DSO boundaries, as they do in many Houdini nodes.
1063  if (grid && grid->type() == GridType::gridType()) {
1064  return StaticPtrCast<GridType>(grid);
1065  }
1066  return typename GridType::Ptr();
1067 }
1068 
1069 
1070 template<typename GridType>
1071 inline typename GridType::ConstPtr
1073 {
1074  return ConstPtrCast<const GridType>(
1075  GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1076 }
1077 
1078 
1079 template<typename GridType>
1080 inline typename GridType::ConstPtr
1082 {
1083  return ConstPtrCast<const GridType>(GridBase::grid<GridType>(grid));
1084 }
1085 
1086 
1087 template<typename GridType>
1088 inline typename GridType::ConstPtr
1090 {
1091  return ConstPtrCast<const GridType>(
1092  GridBase::grid<GridType>(ConstPtrCast<GridBase>(grid)));
1093 }
1094 
1095 
1096 inline TreeBase::Ptr
1098 {
1099  return ConstPtrCast<TreeBase>(this->constBaseTreePtr());
1100 }
1101 
1102 
1103 inline void
1105 {
1106  if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
1107  mTransform = xform;
1108 }
1109 
1110 
1112 
1113 
1114 template<typename TreeT>
1115 inline Grid<TreeT>::Grid(): mTree(new TreeType)
1116 {
1117 }
1118 
1119 
1120 template<typename TreeT>
1121 inline Grid<TreeT>::Grid(const ValueType &background): mTree(new TreeType(background))
1122 {
1123 }
1124 
1125 
1126 template<typename TreeT>
1127 inline Grid<TreeT>::Grid(TreePtrType tree): mTree(tree)
1128 {
1129  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1130 }
1131 
1132 
1133 template<typename TreeT>
1134 inline Grid<TreeT>::Grid(const Grid& other):
1135  GridBase(other),
1136  mTree(StaticPtrCast<TreeType>(other.mTree->copy()))
1137 {
1138 }
1139 
1140 
1141 template<typename TreeT>
1142 template<typename OtherTreeType>
1144  GridBase(other),
1145  mTree(new TreeType(other.constTree()))
1146 {
1147 }
1148 
1149 
1150 #ifdef OPENVDB_3_ABI_COMPATIBLE
1151 template<typename TreeT>
1152 inline Grid<TreeT>::Grid(const Grid& other, ShallowCopy):
1153  GridBase(other, ShallowCopy()),
1154  mTree(other.mTree)
1155 {
1156 }
1157 #else
1158 template<typename TreeT>
1160  GridBase(other),
1161  mTree(other.mTree)
1162 {
1163 }
1164 #endif
1165 
1166 
1167 template<typename TreeT>
1168 inline Grid<TreeT>::Grid(const GridBase& other):
1169  GridBase(other),
1170  mTree(new TreeType)
1171 {
1172 }
1173 
1174 
1175 //static
1176 template<typename TreeT>
1177 inline typename Grid<TreeT>::Ptr
1179 {
1180  return Grid::create(zeroVal<ValueType>());
1181 }
1182 
1183 
1184 //static
1185 template<typename TreeT>
1186 inline typename Grid<TreeT>::Ptr
1188 {
1189  return Ptr(new Grid(background));
1190 }
1191 
1192 
1193 //static
1194 template<typename TreeT>
1195 inline typename Grid<TreeT>::Ptr
1197 {
1198  return Ptr(new Grid(tree));
1199 }
1200 
1201 
1202 //static
1203 template<typename TreeT>
1204 inline typename Grid<TreeT>::Ptr
1206 {
1207  return Ptr(new Grid(other));
1208 }
1209 
1210 
1212 
1213 
1214 #ifdef OPENVDB_3_ABI_COMPATIBLE
1215 
1216 template<typename TreeT>
1217 inline typename Grid<TreeT>::Ptr
1218 Grid<TreeT>::copy(CopyPolicy treePolicy) const
1219 {
1220  Ptr ret;
1221  switch (treePolicy) {
1222  case CP_NEW:
1223  ret.reset(new Grid(*this, ShallowCopy()));
1224  ret->newTree();
1225  break;
1226  case CP_COPY:
1227  ret.reset(new Grid(*this));
1228  break;
1229  case CP_SHARE:
1230  ret.reset(new Grid(*this, ShallowCopy()));
1231  break;
1232  }
1233  return ret;
1234 }
1235 
1236 
1237 template<typename TreeT>
1238 inline GridBase::Ptr
1239 Grid<TreeT>::copyGrid(CopyPolicy treePolicy) const
1240 {
1241  return this->copy(treePolicy);
1242 }
1243 
1244 #else // !OPENVDB_3_ABI_COMPATIBLE
1245 
1246 template<typename TreeT>
1247 inline typename Grid<TreeT>::ConstPtr
1249 {
1250  return ConstPtr{new Grid{*const_cast<Grid*>(this), ShallowCopy{}}};
1251 }
1252 
1253 template<typename TreeT>
1254 inline typename Grid<TreeT>::Ptr
1256 {
1257  return Ptr{new Grid{*this, ShallowCopy{}}};
1258 }
1259 
1260 
1261 template<typename TreeT>
1262 inline typename Grid<TreeT>::Ptr
1264 {
1265  Ptr result{new Grid{*const_cast<Grid*>(this), ShallowCopy{}}};
1266  result->newTree();
1267  return result;
1268 }
1269 
1270 
1271 template<typename TreeT>
1272 inline GridBase::Ptr
1274 {
1275  return this->copy();
1276 }
1277 
1278 template<typename TreeT>
1279 inline GridBase::ConstPtr
1281 {
1282  return this->copy();
1283 }
1284 
1285 
1286 template<typename TreeT>
1287 inline GridBase::Ptr
1289 {
1290  return this->copyWithNewTree();
1291 }
1292 
1293 #endif // OPENVDB_3_ABI_COMPATIBLE
1294 
1295 
1297 
1298 
1299 template<typename TreeT>
1300 inline void
1302 {
1303  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1304  if (tree->type() != TreeType::treeType()) {
1305  OPENVDB_THROW(TypeError, "Cannot assign a tree of type "
1306  + tree->type() + " to a grid of type " + this->type());
1307  }
1308  mTree = StaticPtrCast<TreeType>(tree);
1309 }
1310 
1311 
1312 template<typename TreeT>
1313 inline void
1315 {
1316  mTree.reset(new TreeType(this->background()));
1317 }
1318 
1319 
1321 
1322 
1323 template<typename TreeT>
1324 inline void
1325 Grid<TreeT>::sparseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1326 {
1327  tree().sparseFill(bbox, value, active);
1328 }
1329 
1330 
1331 template<typename TreeT>
1332 inline void
1333 Grid<TreeT>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1334 {
1335  this->sparseFill(bbox, value, active);
1336 }
1337 
1338 template<typename TreeT>
1339 inline void
1340 Grid<TreeT>::denseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1341 {
1342  tree().denseFill(bbox, value, active);
1343 }
1344 
1345 template<typename TreeT>
1346 inline void
1347 Grid<TreeT>::pruneGrid(float tolerance)
1348 {
1349  this->tree().prune(ValueType(zeroVal<ValueType>() + tolerance));
1350 }
1351 
1352 #ifndef OPENVDB_2_ABI_COMPATIBLE
1353 template<typename TreeT>
1354 inline void
1355 Grid<TreeT>::clip(const CoordBBox& bbox)
1356 {
1357  tree().clip(bbox);
1358 }
1359 #endif
1360 
1361 
1362 template<typename TreeT>
1363 inline void
1365 {
1366  tree().merge(other.tree(), policy);
1367 }
1368 
1369 
1370 template<typename TreeT>
1371 template<typename OtherTreeType>
1372 inline void
1374 {
1375  tree().topologyUnion(other.tree());
1376 }
1377 
1378 
1379 template<typename TreeT>
1380 template<typename OtherTreeType>
1381 inline void
1383 {
1384  tree().topologyIntersection(other.tree());
1385 }
1386 
1387 
1388 template<typename TreeT>
1389 template<typename OtherTreeType>
1390 inline void
1392 {
1393  tree().topologyDifference(other.tree());
1394 }
1395 
1396 
1398 
1399 
1400 template<typename TreeT>
1401 inline void
1403 {
1404  tree().evalMinMax(minVal, maxVal);
1405 }
1406 
1407 
1408 template<typename TreeT>
1409 inline CoordBBox
1411 {
1412  CoordBBox bbox;
1413  tree().evalActiveVoxelBoundingBox(bbox);
1414  return bbox;
1415 }
1416 
1417 
1418 template<typename TreeT>
1419 inline Coord
1421 {
1422  Coord dim;
1423  const bool nonempty = tree().evalActiveVoxelDim(dim);
1424  return (nonempty ? dim : Coord());
1425 }
1426 
1427 
1429 
1430 
1433 
1434 template<typename TreeT>
1435 inline void
1436 Grid<TreeT>::readTopology(std::istream& is)
1437 {
1438  tree().readTopology(is, saveFloatAsHalf());
1439 }
1440 
1441 
1442 template<typename TreeT>
1443 inline void
1444 Grid<TreeT>::writeTopology(std::ostream& os) const
1445 {
1446  tree().writeTopology(os, saveFloatAsHalf());
1447 }
1448 
1449 
1450 template<typename TreeT>
1451 inline void
1452 Grid<TreeT>::readBuffers(std::istream& is)
1453 {
1455  tree().readBuffers(is, saveFloatAsHalf());
1456  } else {
1457  uint16_t numPasses = 1;
1458  is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
1460  assert(bool(meta));
1461  for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1462  uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1463  meta->setPass(pass);
1464  tree().readBuffers(is, saveFloatAsHalf());
1465  }
1466  }
1467 }
1468 
1469 
1470 #ifndef OPENVDB_2_ABI_COMPATIBLE
1471 
1474 template<typename TreeT>
1475 inline void
1476 Grid<TreeT>::readBuffers(std::istream& is, const CoordBBox& bbox)
1477 {
1479  tree().readBuffers(is, bbox, saveFloatAsHalf());
1480  } else {
1481  uint16_t numPasses = 1;
1482  is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
1484  assert(bool(meta));
1485  for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1486  uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1487  meta->setPass(pass);
1488  tree().readBuffers(is, saveFloatAsHalf());
1489  }
1490  // Cannot clip inside readBuffers() when using multiple passes,
1491  // so instead clip afterwards.
1492  tree().clip(bbox);
1493  }
1494 }
1495 
1496 
1497 template<typename TreeT>
1498 inline void
1500 {
1501  tree().readNonresidentBuffers();
1502 }
1503 
1504 #endif // !OPENVDB_2_ABI_COMPATIBLE
1505 
1506 
1507 template<typename TreeT>
1508 inline void
1509 Grid<TreeT>::writeBuffers(std::ostream& os) const
1510 {
1511  if (!hasMultiPassIO()) {
1512  tree().writeBuffers(os, saveFloatAsHalf());
1513  } else {
1514  // Determine how many leaf buffer passes are required for this grid
1516  assert(bool(meta));
1517  uint16_t numPasses = 1;
1518  meta->setCountingPasses(true);
1519  meta->setPass(0);
1520  tree().writeBuffers(os, saveFloatAsHalf());
1521  numPasses = static_cast<uint16_t>(meta->pass());
1522  os.write(reinterpret_cast<const char*>(&numPasses), sizeof(uint16_t));
1523  meta->setCountingPasses(false);
1524 
1525  // Save out the data blocks of the grid.
1526  for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1527  uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1528  meta->setPass(pass);
1529  tree().writeBuffers(os, saveFloatAsHalf());
1530  }
1531  }
1532 }
1533 
1534 
1535 //static
1536 template<typename TreeT>
1537 inline bool
1539 {
1541 }
1542 
1543 
1544 template<typename TreeT>
1545 inline void
1546 Grid<TreeT>::print(std::ostream& os, int verboseLevel) const
1547 {
1548  tree().print(os, verboseLevel);
1549 
1550  if (metaCount() > 0) {
1551  os << "Additional metadata:" << std::endl;
1552  for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1553  os << " " << it->first;
1554  if (it->second) {
1555  const std::string value = it->second->str();
1556  if (!value.empty()) os << ": " << value;
1557  }
1558  os << "\n";
1559  }
1560  }
1561 
1562  os << "Transform:" << std::endl;
1563  transform().print(os, /*indent=*/" ");
1564  os << std::endl;
1565 }
1566 
1567 
1569 
1570 
1571 template<typename GridType>
1572 inline typename GridType::Ptr
1573 createGrid(const typename GridType::ValueType& background)
1574 {
1575  return GridType::create(background);
1576 }
1577 
1578 
1579 template<typename GridType>
1580 inline typename GridType::Ptr
1582 {
1583  return GridType::create();
1584 }
1585 
1586 
1587 template<typename TreePtrType>
1590 {
1591  using TreeType = typename TreePtrType::element_type;
1592  return Grid<TreeType>::create(tree);
1593 }
1594 
1595 
1596 template<typename GridType>
1597 typename GridType::Ptr
1599 {
1600  using ValueType = typename GridType::ValueType;
1601 
1602  // GridType::ValueType is required to be a floating-point scalar.
1603  static_assert(std::is_floating_point<ValueType>::value,
1604  "level-set grids must be floating-point-valued");
1605 
1606  typename GridType::Ptr grid = GridType::create(
1607  /*background=*/static_cast<ValueType>(voxelSize * halfWidth));
1608  grid->setTransform(math::Transform::createLinearTransform(voxelSize));
1609  grid->setGridClass(GRID_LEVEL_SET);
1610  return grid;
1611 }
1612 
1613 } // namespace OPENVDB_VERSION_NAME
1614 } // namespace openvdb
1615 
1616 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
1617 
1618 // Copyright (c) 2012-2017 DreamWorks Animation LLC
1619 // All rights reserved. This software is distributed under the
1620 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:670
~Grid() override
Definition: Grid.h:573
SharedPtr< Transform > Ptr
Definition: Transform.h:69
GridNamePred(const Name &_name)
Definition: Grid.h:460
static const TreeType & tree(const GridType &g)
Definition: Grid.h:985
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:194
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:479
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:399
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:997
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:628
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:513
Vec3d voxelSize() const
Return the size of this grid&#39;s voxels.
Definition: Grid.h:358
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1035
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:970
UnsafeAccessor getUnsafeAccessor()
Return an accessor that provides random read and write access to this grid&#39;s voxels. The accessor is unsafe in the sense that it is not registered by the tree of this grid. In some rare cases this can give a performance advantage over a registered accessor but it is unsafe if the tree topology is modified.
Definition: Grid.h:644
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:1382
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1007
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1005
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:675
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid&#39;s voxels. The accessor is safe in the sense that it is registered by the tree of this grid.
Definition: Grid.h:635
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:986
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:458
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:444
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:438
MetadataMap::const_iterator ConstMetaIterator
Definition: MetaMap.h:55
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:878
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 ...
Calculate an axis-aligned bounding box in index space from a bounding sphere in world space...
Definition: Transform.h:66
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1509
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1013
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:938
typename GridType::Ptr GridPtrType
Definition: Grid.h:974
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:68
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1589
double Real
Definition: Types.h:63
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:461
typename TreeType::Ptr TreePtrType
Definition: Grid.h:969
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1009
Abstract base class for typed grids.
Definition: Grid.h:103
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:449
const ValueType & background() const
Return this grid&#39;s background value.
Definition: Grid.h:625
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:1263
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid&#39;s transform to the given coordinates.
Definition: Grid.h:367
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:954
const TreeType & tree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:797
Definition: ValueAccessor.h:219
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:363
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:294
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
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:1391
SharedPtr< T > StaticPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that points to the same object as the given pointer after a static_cast...
Definition: Types.h:161
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:941
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:971
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1420
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:968
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46
static TreeType & tree(GridType &g)
Definition: Grid.h:983
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1402
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1301
typename _TreeType::BuildType BuildType
Definition: Grid.h:508
typename TreeType::Ptr TreePtrType
Definition: Grid.h:998
static const TreeType & constTree(GridType &g)
Definition: Grid.h:957
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:1499
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:945
_TreeType TreeType
Definition: Grid.h:937
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:976
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
Definition: Grid.h:1538
math::Transform & transform()
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:346
MetaIterator endMeta()
Definition: MetaMap.h:112
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:293
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:441
SharedPtr< TreeBase > Ptr
Definition: Tree.h:67
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:510
static TreeType & tree(TreeType &t)
Definition: Grid.h:982
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:630
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:607
TreeType & tree()
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:796
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:946
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:788
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:505
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:339
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid&#39;s voxel at position (x, y, z).
Definition: Grid.h:361
~GridBase() override
Definition: Grid.h:112
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:1097
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:920
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:1340
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:989
Index64 memUsage() const override
Definition: Grid.h:777
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1364
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:517
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1115
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:451
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1347
GridClass
Definition: Types.h:262
Name name
Definition: Grid.h:462
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:454
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1178
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1452
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:270
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:443
const math::Transform & constTransform() const
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:348
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:401
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:956
_TreeType TreeType
Definition: Grid.h:967
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1019
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1020
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:500
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:787
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:676
#define OPENVDB_VERSION_NAME
Definition: version.h:43
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:506
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1000
typename _TreeType::ValueType ValueType
Definition: Grid.h:507
Vec3< double > Vec3d
Definition: Vec3.h:708
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1008
static const char *const META_GRID_CREATOR
Definition: Grid.h:291
Definition: Exceptions.h:91
typename TreeType::ValueType ValueType
Definition: Grid.h:977
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid&#39;s voxels.
Definition: Grid.h:648
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:950
static const TreeType & tree(const GridType &g)
Definition: Grid.h:955
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:518
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:367
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:940
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:855
static const TreeType & constTree(GridType &g)
Definition: Grid.h:987
static TreeType & tree(TreeType &t)
Definition: Grid.h:952
OPENVDB_API uint32_t getGridClass(std::ios_base &)
Return the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently being read from or writte...
Definition: Exceptions.h:39
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:984
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1014
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:442
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1015
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:1436
const math::Transform & transform() const
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:347
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:515
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:769
SharedPtr< const Transform > ConstPtr
Definition: Transform.h:70
_TreeType TreeType
Definition: Grid.h:504
SharedPtr< StreamMetadata > Ptr
Definition: io.h:59
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:453
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:1598
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:1444
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:296
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:447
static Transform::Ptr createLinearTransform(double voxelSize=1.0)
Create and return a shared pointer to a new transform.
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:980
typename TreeType::ValueType ValueType
Definition: Grid.h:1006
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:299
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:409
void print(std::ostream &os=std::cout, const std::string &indent="") const
Print a description of this transform.
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:949
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:297
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:1325
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:1373
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:298
static TreeType & tree(GridType &g)
Definition: Grid.h:953
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:1059
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1017
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:664
SharedPtr< MetaMap > Ptr
Definition: MetaMap.h:49
Definition: Exceptions.h:92
const TreeType & constTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:798
const TreeBase & constBaseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:186
uint64_t Index64
Definition: Types.h:56
MergePolicy
Definition: Types.h:315
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:519
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:979
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:613
std::string Name
Definition: Name.h:44
GridBase(const GridBase &other)
Deep copy another grid&#39;s metadata and transform.
Definition: Grid.h:412
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:663
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:446
const TreeBase & baseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:185
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1314
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:959
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1355
typename GridType::Ptr GridPtrType
Definition: Grid.h:1003
tree::TreeBase TreeBase
Definition: Grid.h:52
static TreeType & tree(TreeType &t)
Definition: Grid.h:1011
std::shared_ptr< T > SharedPtr
Definition: Types.h:130
typename TreeType::ValueType ValueType
Definition: Grid.h:947
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid&#39;s.
VecType
Definition: Types.h:292
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:948
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1104
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:338
Name valueType() const override
Return the name of the type of a voxel&#39;s value (e.g., "float" or "vec3d").
Definition: Grid.h:620
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:935
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1410
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:436
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:502
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:975
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:514
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:1333
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:958
GridBase::Ptr copyGrid() override
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition: Grid.h:1273
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:300
SharedPtr< GridBase > Ptr
Definition: Grid.h:106
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:511
static const char *const META_GRID_CLASS
Definition: Grid.h:290
typename GridType::Ptr GridPtrType
Definition: Grid.h:944
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:1255
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:437
Name type() const override
Return the name of this grid&#39;s type.
Definition: Grid.h:611
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:851
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:156
Base class for typed trees.
Definition: Tree.h:64
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:512
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:452
static const char *const META_GRID_NAME
Definition: Grid.h:292
size_t metaCount() const
Definition: MetaMap.h:118
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:175
MetaIterator beginMeta()
Definition: MetaMap.h:111
static TreeType & tree(GridType &g)
Definition: Grid.h:1012
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:978
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:853
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1016
SharedPtr< Grid > Ptr
Definition: Grid.h:501
static const char *const META_VECTOR_TYPE
Definition: Grid.h:295
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:448
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:999
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:669
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:894
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:520
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:107
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:439
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1546
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:529
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:1081
Definition: Types.h:264
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1018
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:789
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1004
typename TreeType::Ptr TreePtrType
Definition: Grid.h:939
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:988
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:1288