OpenVDB  3.2.0
Grid.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2016 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 <iostream>
35 #include <set>
36 #include <vector>
37 #include <boost/static_assert.hpp>
38 #include <boost/type_traits/remove_const.hpp>
39 #include <boost/type_traits/is_floating_point.hpp>
40 #include <openvdb/Types.h>
41 #include <openvdb/util/Name.h>
42 #include <openvdb/math/Transform.h>
43 #include <openvdb/tree/Tree.h>
44 #include <openvdb/metadata/MetaMap.h>
45 #include <openvdb/Exceptions.h>
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:
106  typedef boost::shared_ptr<GridBase> Ptr;
107  typedef boost::shared_ptr<const GridBase> ConstPtr;
108 
109  typedef Ptr (*GridFactory)();
110 
111 
112  virtual ~GridBase() {}
113 
116  virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const = 0;
117 
119  virtual GridBase::Ptr deepCopyGrid() const = 0;
120 
121 
122  //
123  // Registry methods
124  //
126  static Ptr createGrid(const Name& type);
127 
129  static bool isRegistered(const Name &type);
130 
132  static void clearRegistry();
133 
134 
135  //
136  // Grid type methods
137  //
139  virtual Name type() const = 0;
141  virtual Name valueType() const = 0;
142 
144  template<typename GridType>
145  bool isType() const { return (this->type() == GridType::gridType()); }
146 
148  template<typename GridType>
151  static typename GridType::Ptr grid(const GridBase::Ptr&);
152  template<typename GridType>
153  static typename GridType::ConstPtr grid(const GridBase::ConstPtr&);
154  template<typename GridType>
155  static typename GridType::ConstPtr constGrid(const GridBase::Ptr&);
156  template<typename GridType>
157  static typename GridType::ConstPtr constGrid(const GridBase::ConstPtr&);
159 
161  TreeBase::Ptr baseTreePtr();
164  TreeBase::ConstPtr baseTreePtr() const { return this->constBaseTreePtr(); }
165  virtual TreeBase::ConstPtr constBaseTreePtr() const = 0;
167 
169  TreeBase& baseTree() { return const_cast<TreeBase&>(this->constBaseTree()); }
174  const TreeBase& baseTree() const { return this->constBaseTree(); }
175  const TreeBase& constBaseTree() const { return *(this->constBaseTreePtr()); }
177 
183  virtual void setTree(TreeBase::Ptr) = 0;
184 
186  virtual void newTree() = 0;
187 
189  virtual bool empty() const = 0;
191  virtual void clear() = 0;
192 
198  virtual void pruneGrid(float tolerance = 0.0) = 0;
199 
200 #ifndef OPENVDB_2_ABI_COMPATIBLE
201  void clipGrid(const BBoxd&);
206 
211  virtual void clip(const CoordBBox&) = 0;
212 #endif
213 
214 
215  //
216  // Metadata
217  //
219  std::string getName() const;
221  void setName(const std::string&);
222 
224  std::string getCreator() const;
226  void setCreator(const std::string&);
227 
230  bool saveFloatAsHalf() const;
231  void setSaveFloatAsHalf(bool);
232 
234  GridClass getGridClass() const;
236  void setGridClass(GridClass);
238  void clearGridClass();
239 
241  static std::string gridClassToString(GridClass);
243  static std::string gridClassToMenuName(GridClass);
247  static GridClass stringToGridClass(const std::string&);
248 
251  VecType getVectorType() const;
254  void setVectorType(VecType);
256  void clearVectorType();
257 
259  static std::string vecTypeToString(VecType);
262  static std::string vecTypeExamples(VecType);
265  static std::string vecTypeDescription(VecType);
266  static VecType stringToVecType(const std::string&);
267 
271  bool isInWorldSpace() const;
273  void setIsInWorldSpace(bool);
274 
275  // Standard metadata field names
276  // (These fields should normally not be accessed directly, but rather
277  // via the accessor methods above, when available.)
278  // Note: Visual C++ requires these declarations to be separate statements.
279  static const char* const META_GRID_CLASS;
280  static const char* const META_GRID_CREATOR;
281  static const char* const META_GRID_NAME;
282  static const char* const META_SAVE_HALF_FLOAT;
283  static const char* const META_IS_LOCAL_SPACE;
284  static const char* const META_VECTOR_TYPE;
285  static const char* const META_FILE_BBOX_MIN;
286  static const char* const META_FILE_BBOX_MAX;
287  static const char* const META_FILE_COMPRESSION;
288  static const char* const META_FILE_MEM_BYTES;
289  static const char* const META_FILE_VOXEL_COUNT;
290 
291 
292  //
293  // Statistics
294  //
296  virtual Index64 activeVoxelCount() const = 0;
297 
300  virtual CoordBBox evalActiveVoxelBoundingBox() const = 0;
301 
303  virtual Coord evalActiveVoxelDim() const = 0;
304 
306  virtual Index64 memUsage() const = 0;
307 
312  void addStatsMetadata();
317  MetaMap::Ptr getStatsMetadata() const;
318 
319 
320  //
321  // Transform methods
322  //
324  math::Transform::Ptr transformPtr() { return mTransform; }
327  math::Transform::ConstPtr transformPtr() const { return mTransform; }
328  math::Transform::ConstPtr constTransformPtr() const { return mTransform; }
330 
331  math::Transform& transform() { return *mTransform; }
336  const math::Transform& transform() const { return *mTransform; }
337  const math::Transform& constTransform() const { return *mTransform; }
339  void setTransform(math::Transform::Ptr);
345 
347  Vec3d voxelSize() const { return transform().voxelSize(); }
350  Vec3d voxelSize(const Vec3d& xyz) const { return transform().voxelSize(xyz); }
352  bool hasUniformVoxels() const { return mTransform->hasUniformScale(); }
354  Vec3d indexToWorld(const Vec3d& xyz) const { return transform().indexToWorld(xyz); }
356  Vec3d indexToWorld(const Coord& ijk) const { return transform().indexToWorld(ijk); }
358  Vec3d worldToIndex(const Vec3d& xyz) const { return transform().worldToIndex(xyz); }
360 
361 
362  //
363  // I/O methods
364  //
367  virtual void readTopology(std::istream&) = 0;
370  virtual void writeTopology(std::ostream&) const = 0;
371 
373  virtual void readBuffers(std::istream&) = 0;
374 #ifndef OPENVDB_2_ABI_COMPATIBLE
375  virtual void readBuffers(std::istream&, const CoordBBox&) = 0;
382  virtual void readNonresidentBuffers() const = 0;
383 #endif
384  virtual void writeBuffers(std::ostream&) const = 0;
386 
388  void readTransform(std::istream& is) { transform().read(is); }
390  void writeTransform(std::ostream& os) const { transform().write(os); }
391 
393  virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const = 0;
394 
395 
396 protected:
398  GridBase(): mTransform(math::Transform::createLinearTransform()) {}
399 
401  GridBase(const GridBase& other): MetaMap(other), mTransform(other.mTransform->copy()) {}
402 
404  GridBase(const GridBase& other, ShallowCopy): MetaMap(other), mTransform(other.mTransform) {}
405 
407  static void registerGrid(const Name& type, GridFactory);
409  static void unregisterGrid(const Name& type);
410 
411 
412 private:
413  math::Transform::Ptr mTransform;
414 }; // class GridBase
415 
416 
418 
419 
420 typedef std::vector<GridBase::Ptr> GridPtrVec;
421 typedef GridPtrVec::iterator GridPtrVecIter;
422 typedef GridPtrVec::const_iterator GridPtrVecCIter;
423 typedef boost::shared_ptr<GridPtrVec> GridPtrVecPtr;
424 
425 typedef std::vector<GridBase::ConstPtr> GridCPtrVec;
426 typedef GridCPtrVec::iterator GridCPtrVecIter;
427 typedef GridCPtrVec::const_iterator GridCPtrVecCIter;
428 typedef boost::shared_ptr<GridCPtrVec> GridCPtrVecPtr;
429 
430 typedef std::set<GridBase::Ptr> GridPtrSet;
431 typedef GridPtrSet::iterator GridPtrSetIter;
432 typedef GridPtrSet::const_iterator GridPtrSetCIter;
433 typedef boost::shared_ptr<GridPtrSet> GridPtrSetPtr;
434 
435 typedef std::set<GridBase::ConstPtr> GridCPtrSet;
436 typedef GridCPtrSet::iterator GridCPtrSetIter;
437 typedef GridCPtrSet::const_iterator GridCPtrSetCIter;
438 typedef boost::shared_ptr<GridCPtrSet> GridCPtrSetPtr;
439 
440 
443 {
444  GridNamePred(const Name& _name): name(_name) {}
445  bool operator()(const GridBase::ConstPtr& g) const { return g && g->getName() == name; }
447 };
448 
450 template<typename GridPtrContainerT>
451 inline typename GridPtrContainerT::value_type
452 findGridByName(const GridPtrContainerT& container, const Name& name)
453 {
454  typedef typename GridPtrContainerT::value_type GridPtrT;
455  typename GridPtrContainerT::const_iterator it =
456  std::find_if(container.begin(), container.end(), GridNamePred(name));
457  return (it == container.end() ? GridPtrT() : *it);
458 }
459 
461 template<typename KeyT, typename GridPtrT>
462 inline GridPtrT
463 findGridByName(const std::map<KeyT, GridPtrT>& container, const Name& name)
464 {
465  typedef std::map<KeyT, GridPtrT> GridPtrMapT;
466  for (typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
467  it != end; ++it)
468  {
469  const GridPtrT& grid = it->second;
470  if (grid && grid->getName() == name) return grid;
471  }
472  return GridPtrT();
473 }
475 
476 
478 
479 
481 template<typename _TreeType>
482 class Grid: public GridBase
483 {
484 public:
485  typedef boost::shared_ptr<Grid> Ptr;
486  typedef boost::shared_ptr<const Grid> ConstPtr;
487 
488  typedef _TreeType TreeType;
489  typedef typename _TreeType::Ptr TreePtrType;
490  typedef typename _TreeType::ConstPtr ConstTreePtrType;
491  typedef typename _TreeType::ValueType ValueType;
492  typedef typename _TreeType::BuildType BuildType;
493 
494  typedef typename _TreeType::ValueOnIter ValueOnIter;
495  typedef typename _TreeType::ValueOnCIter ValueOnCIter;
496  typedef typename _TreeType::ValueOffIter ValueOffIter;
497  typedef typename _TreeType::ValueOffCIter ValueOffCIter;
498  typedef typename _TreeType::ValueAllIter ValueAllIter;
499  typedef typename _TreeType::ValueAllCIter ValueAllCIter;
500 
505 
512  template<typename OtherValueType>
513  struct ValueConverter {
515  };
516 
518  static Ptr create(const ValueType& background);
520  static Ptr create();
523  static Ptr create(TreePtrType);
526  static Ptr create(const GridBase& other);
527 
528 
530  Grid();
532  explicit Grid(const ValueType& background);
536  explicit Grid(TreePtrType);
538  Grid(const Grid&);
544  template<typename OtherTreeType>
545  explicit Grid(const Grid<OtherTreeType>&);
547  Grid(const Grid&, ShallowCopy);
550  explicit Grid(const GridBase&);
551 
552  virtual ~Grid() {}
553 
555  Ptr copy(CopyPolicy treePolicy = CP_SHARE) const;
561  virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const;
563 
564  Ptr deepCopy() const { return Ptr(new Grid(*this)); }
566  virtual GridBase::Ptr deepCopyGrid() const { return this->deepCopy(); }
568 
570  virtual Name type() const { return this->gridType(); }
572  static Name gridType() { return TreeType::treeType(); }
573 
574 
575  //
576  // Voxel access methods
577  //
579  virtual Name valueType() const { return tree().valueType(); }
580 
584  const ValueType& background() const { return mTree->background(); }
585 
587  virtual bool empty() const { return tree().empty(); }
589  virtual void clear() { tree().clear(); }
590 
594  Accessor getAccessor() { return Accessor(tree()); }
603  UnsafeAccessor getUnsafeAccessor() { return UnsafeAccessor(tree()); }
605  ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
607  ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
609  ConstUnsafeAccessor getConstUnsafeAccessor() const { return ConstUnsafeAccessor(tree()); }
618 
620  ValueOnIter beginValueOn() { return tree().beginValueOn(); }
622  ValueOnCIter beginValueOn() const { return tree().cbeginValueOn(); }
623  ValueOnCIter cbeginValueOn() const { return tree().cbeginValueOn(); }
625 
626  ValueOffIter beginValueOff() { return tree().beginValueOff(); }
628  ValueOffCIter beginValueOff() const { return tree().cbeginValueOff(); }
629  ValueOffCIter cbeginValueOff() const { return tree().cbeginValueOff(); }
631 
632  ValueAllIter beginValueAll() { return tree().beginValueAll(); }
634  ValueAllCIter beginValueAll() const { return tree().cbeginValueAll(); }
635  ValueAllCIter cbeginValueAll() const { return tree().cbeginValueAll(); }
637 
639  void evalMinMax(ValueType& minVal, ValueType& maxVal) const;
640 
642  void sparseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
651  void fill(const CoordBBox& bbox, const ValueType& value, bool active = true)
652  {
653  this->sparseFill(bbox, value, active);
654  }
656 
666  void denseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
667 
669  virtual void pruneGrid(float tolerance = 0.0);
670 
671 #ifndef OPENVDB_2_ABI_COMPATIBLE
672  virtual void clip(const CoordBBox&);
677 #endif
678 
684  void merge(Grid& other, MergePolicy policy = MERGE_ACTIVE_STATES);
685 
699  template<typename OtherTreeType>
700  void topologyUnion(const Grid<OtherTreeType>& other);
701 
714  template<typename OtherTreeType>
715  void topologyIntersection(const Grid<OtherTreeType>& other);
716 
727  template<typename OtherTreeType>
728  void topologyDifference(const Grid<OtherTreeType>& other);
729 
730  //
731  // Statistics
732  //
734  virtual Index64 activeVoxelCount() const { return tree().activeVoxelCount(); }
736  virtual CoordBBox evalActiveVoxelBoundingBox() const;
738  virtual Coord evalActiveVoxelDim() const;
739 
742  virtual Index64 memUsage() const { return tree().memUsage(); }
743 
744 
745  //
746  // Tree methods
747  //
749  TreePtrType treePtr() { return mTree; }
752  ConstTreePtrType treePtr() const { return mTree; }
753  ConstTreePtrType constTreePtr() const { return mTree; }
754  virtual TreeBase::ConstPtr constBaseTreePtr() const { return mTree; }
756 
757  TreeType& tree() { return *mTree; }
762  const TreeType& tree() const { return *mTree; }
763  const TreeType& constTree() const { return *mTree; }
765 
771  virtual void setTree(TreeBase::Ptr);
772 
775  virtual void newTree();
776 
777 
778  //
779  // I/O methods
780  //
783  virtual void readTopology(std::istream&);
786  virtual void writeTopology(std::ostream&) const;
787 
789  virtual void readBuffers(std::istream&);
790 #ifndef OPENVDB_2_ABI_COMPATIBLE
791  virtual void readBuffers(std::istream&, const CoordBBox&);
798  virtual void readNonresidentBuffers() const;
799 #endif
800  virtual void writeBuffers(std::ostream&) const;
802 
804  virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const;
805 
806 
807  //
808  // Registry methods
809  //
813  static void registerGrid() { GridBase::registerGrid(Grid::gridType(), Grid::factory); }
816 
817 
818 private:
820  Grid& operator=(const Grid& other);
821 
823  static GridBase::Ptr factory() { return Grid::create(); }
824 
825  TreePtrType mTree;
826 }; // class Grid
827 
828 
830 
831 
839 template<typename GridType>
840 inline typename GridType::Ptr
842 {
843  return GridBase::grid<GridType>(grid);
844 }
845 
846 
855 template<typename GridType>
856 inline typename GridType::ConstPtr
858 {
859  return GridBase::constGrid<GridType>(grid);
860 }
861 
862 
864 
865 
872 template<typename GridType>
873 inline typename GridType::Ptr
875 {
876  if (!grid || !grid->isType<GridType>()) return typename GridType::Ptr();
877  return gridPtrCast<GridType>(grid->deepCopyGrid());
878 }
879 
880 
881 template<typename GridType>
882 inline typename GridType::Ptr
884 {
885  if (!grid.isType<GridType>()) return typename GridType::Ptr();
886  return gridPtrCast<GridType>(grid.deepCopyGrid());
887 }
889 
890 
892 
893 
895 template<typename _TreeType>
899 {
900  typedef _TreeType TreeType;
901  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
902  typedef typename TreeType::Ptr TreePtrType;
903  typedef typename TreeType::ConstPtr ConstTreePtrType;
904  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
907  typedef typename GridType::Ptr GridPtrType;
910  typedef typename TreeType::ValueType ValueType;
914 
915  static TreeType& tree(TreeType& t) { return t; }
916  static TreeType& tree(GridType& g) { return g.tree(); }
917  static const TreeType& tree(const TreeType& t) { return t; }
918  static const TreeType& tree(const GridType& g) { return g.tree(); }
919  static const TreeType& constTree(TreeType& t) { return t; }
920  static const TreeType& constTree(GridType& g) { return g.constTree(); }
921  static const TreeType& constTree(const TreeType& t) { return t; }
922  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
923 };
924 
925 
927 template<typename _TreeType>
928 struct TreeAdapter<Grid<_TreeType> >
929 {
930  typedef _TreeType TreeType;
931  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
932  typedef typename TreeType::Ptr TreePtrType;
933  typedef typename TreeType::ConstPtr ConstTreePtrType;
934  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
937  typedef typename GridType::Ptr GridPtrType;
940  typedef typename TreeType::ValueType ValueType;
944 
945  static TreeType& tree(TreeType& t) { return t; }
946  static TreeType& tree(GridType& g) { return g.tree(); }
947  static const TreeType& tree(const TreeType& t) { return t; }
948  static const TreeType& tree(const GridType& g) { return g.tree(); }
949  static const TreeType& constTree(TreeType& t) { return t; }
950  static const TreeType& constTree(GridType& g) { return g.constTree(); }
951  static const TreeType& constTree(const TreeType& t) { return t; }
952  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
953 };
954 
956 template<typename _TreeType>
957 struct TreeAdapter<tree::ValueAccessor<_TreeType> >
958 {
959  typedef _TreeType TreeType;
960  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
961  typedef typename TreeType::Ptr TreePtrType;
962  typedef typename TreeType::ConstPtr ConstTreePtrType;
963  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
966  typedef typename GridType::Ptr GridPtrType;
969  typedef typename TreeType::ValueType ValueType;
973 
974  static TreeType& tree(TreeType& t) { return t; }
975  static TreeType& tree(GridType& g) { return g.tree(); }
976  static TreeType& tree(AccessorType& a) { return a.tree(); }
977  static const TreeType& tree(const TreeType& t) { return t; }
978  static const TreeType& tree(const GridType& g) { return g.tree(); }
979  static const TreeType& tree(const AccessorType& a) { return a.tree(); }
980  static const TreeType& constTree(TreeType& t) { return t; }
981  static const TreeType& constTree(GridType& g) { return g.constTree(); }
982  static const TreeType& constTree(const TreeType& t) { return t; }
983  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
984 };
985 
987 
988 
990 
991 
992 template<typename GridType>
993 inline typename GridType::Ptr
995 {
996  // The string comparison on type names is slower than a dynamic_pointer_cast, but
997  // it is safer when pointers cross dso boundaries, as they do in many Houdini nodes.
998  if (grid && grid->type() == GridType::gridType()) {
999  return boost::static_pointer_cast<GridType>(grid);
1000  }
1001  return typename GridType::Ptr();
1002 }
1003 
1004 
1005 template<typename GridType>
1006 inline typename GridType::ConstPtr
1008 {
1009  return boost::const_pointer_cast<const GridType>(
1010  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
1011 }
1012 
1013 
1014 template<typename GridType>
1015 inline typename GridType::ConstPtr
1017 {
1018  return boost::const_pointer_cast<const GridType>(GridBase::grid<GridType>(grid));
1019 }
1020 
1021 
1022 template<typename GridType>
1023 inline typename GridType::ConstPtr
1025 {
1026  return boost::const_pointer_cast<const GridType>(
1027  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
1028 }
1029 
1030 
1031 inline TreeBase::Ptr
1033 {
1034  return boost::const_pointer_cast<TreeBase>(this->constBaseTreePtr());
1035 }
1036 
1037 
1038 inline void
1040 {
1041  if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
1042  mTransform = xform;
1043 }
1044 
1045 
1047 
1048 
1049 template<typename TreeT>
1050 inline Grid<TreeT>::Grid(): mTree(new TreeType)
1051 {
1052 }
1053 
1054 
1055 template<typename TreeT>
1056 inline Grid<TreeT>::Grid(const ValueType &background): mTree(new TreeType(background))
1057 {
1058 }
1059 
1060 
1061 template<typename TreeT>
1062 inline Grid<TreeT>::Grid(TreePtrType tree): mTree(tree)
1063 {
1064  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1065 }
1066 
1067 
1068 template<typename TreeT>
1069 inline Grid<TreeT>::Grid(const Grid& other):
1070  GridBase(other),
1071  mTree(boost::static_pointer_cast<TreeType>(other.mTree->copy()))
1072 {
1073 }
1074 
1075 
1076 template<typename TreeT>
1077 template<typename OtherTreeType>
1079  GridBase(other),
1080  mTree(new TreeType(other.constTree()))
1081 {
1082 }
1083 
1084 
1085 template<typename TreeT>
1086 inline Grid<TreeT>::Grid(const Grid& other, ShallowCopy):
1087  GridBase(other, ShallowCopy()),
1088  mTree(other.mTree)
1089 {
1090 }
1091 
1092 
1093 template<typename TreeT>
1094 inline Grid<TreeT>::Grid(const GridBase& other):
1095  GridBase(other),
1096  mTree(new TreeType)
1097 {
1098 }
1099 
1100 
1101 //static
1102 template<typename TreeT>
1103 inline typename Grid<TreeT>::Ptr
1105 {
1106  return Grid::create(zeroVal<ValueType>());
1107 }
1108 
1109 
1110 //static
1111 template<typename TreeT>
1112 inline typename Grid<TreeT>::Ptr
1114 {
1115  return Ptr(new Grid(background));
1116 }
1117 
1118 
1119 //static
1120 template<typename TreeT>
1121 inline typename Grid<TreeT>::Ptr
1123 {
1124  return Ptr(new Grid(tree));
1125 }
1126 
1127 
1128 //static
1129 template<typename TreeT>
1130 inline typename Grid<TreeT>::Ptr
1132 {
1133  return Ptr(new Grid(other));
1134 }
1135 
1136 
1138 
1139 
1140 template<typename TreeT>
1141 inline typename Grid<TreeT>::Ptr
1143 {
1144  Ptr ret;
1145  switch (treePolicy) {
1146  case CP_NEW:
1147  ret.reset(new Grid(*this, ShallowCopy()));
1148  ret->newTree();
1149  break;
1150  case CP_COPY:
1151  ret.reset(new Grid(*this));
1152  break;
1153  case CP_SHARE:
1154  ret.reset(new Grid(*this, ShallowCopy()));
1155  break;
1156  }
1157  return ret;
1158 }
1159 
1160 
1161 template<typename TreeT>
1162 inline GridBase::Ptr
1164 {
1165  return this->copy(treePolicy);
1166 }
1167 
1168 
1170 
1171 
1172 template<typename TreeT>
1173 inline void
1175 {
1176  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1177  if (tree->type() != TreeType::treeType()) {
1178  OPENVDB_THROW(TypeError, "Cannot assign a tree of type "
1179  + tree->type() + " to a grid of type " + this->type());
1180  }
1181  mTree = boost::static_pointer_cast<TreeType>(tree);
1182 }
1183 
1184 
1185 template<typename TreeT>
1186 inline void
1188 {
1189  mTree.reset(new TreeType(this->background()));
1190 }
1191 
1192 
1194 
1195 
1196 template<typename TreeT>
1197 inline void
1198 Grid<TreeT>::sparseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1199 {
1200  tree().sparseFill(bbox, value, active);
1201 }
1202 
1203 template<typename TreeT>
1204 inline void
1205 Grid<TreeT>::denseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1206 {
1207  tree().denseFill(bbox, value, active);
1208 }
1209 
1210 template<typename TreeT>
1211 inline void
1212 Grid<TreeT>::pruneGrid(float tolerance)
1213 {
1214  this->tree().prune(ValueType(zeroVal<ValueType>() + tolerance));
1215 }
1216 
1217 #ifndef OPENVDB_2_ABI_COMPATIBLE
1218 template<typename TreeT>
1219 inline void
1221 {
1222  tree().clip(bbox);
1223 }
1224 #endif
1225 
1226 
1227 template<typename TreeT>
1228 inline void
1230 {
1231  tree().merge(other.tree(), policy);
1232 }
1233 
1234 
1235 template<typename TreeT>
1236 template<typename OtherTreeType>
1237 inline void
1239 {
1240  tree().topologyUnion(other.tree());
1241 }
1242 
1243 
1244 template<typename TreeT>
1245 template<typename OtherTreeType>
1246 inline void
1248 {
1249  tree().topologyIntersection(other.tree());
1250 }
1251 
1252 
1253 template<typename TreeT>
1254 template<typename OtherTreeType>
1255 inline void
1257 {
1258  tree().topologyDifference(other.tree());
1259 }
1260 
1261 
1263 
1264 
1265 template<typename TreeT>
1266 inline void
1268 {
1269  tree().evalMinMax(minVal, maxVal);
1270 }
1271 
1272 
1273 template<typename TreeT>
1274 inline CoordBBox
1276 {
1277  CoordBBox bbox;
1278  tree().evalActiveVoxelBoundingBox(bbox);
1279  return bbox;
1280 }
1281 
1282 
1283 template<typename TreeT>
1284 inline Coord
1286 {
1287  Coord dim;
1288  const bool nonempty = tree().evalActiveVoxelDim(dim);
1289  return (nonempty ? dim : Coord());
1290 }
1291 
1292 
1294 
1295 
1298 
1299 template<typename TreeT>
1300 inline void
1301 Grid<TreeT>::readTopology(std::istream& is)
1302 {
1303  tree().readTopology(is, saveFloatAsHalf());
1304 }
1305 
1306 
1307 template<typename TreeT>
1308 inline void
1309 Grid<TreeT>::writeTopology(std::ostream& os) const
1310 {
1311  tree().writeTopology(os, saveFloatAsHalf());
1312 }
1313 
1314 
1315 template<typename TreeT>
1316 inline void
1317 Grid<TreeT>::readBuffers(std::istream& is)
1318 {
1319  tree().readBuffers(is, saveFloatAsHalf());
1320 }
1321 
1322 
1323 #ifndef OPENVDB_2_ABI_COMPATIBLE
1324 
1325 template<typename TreeT>
1326 inline void
1327 Grid<TreeT>::readBuffers(std::istream& is, const CoordBBox& bbox)
1328 {
1329  tree().readBuffers(is, bbox, saveFloatAsHalf());
1330 }
1331 
1332 
1333 template<typename TreeT>
1334 inline void
1336 {
1337  tree().readNonresidentBuffers();
1338 }
1339 
1340 #endif // !OPENVDB_2_ABI_COMPATIBLE
1341 
1342 
1343 template<typename TreeT>
1344 inline void
1345 Grid<TreeT>::writeBuffers(std::ostream& os) const
1346 {
1347  tree().writeBuffers(os, saveFloatAsHalf());
1348 }
1349 
1350 
1351 template<typename TreeT>
1352 inline void
1353 Grid<TreeT>::print(std::ostream& os, int verboseLevel) const
1354 {
1355  tree().print(os, verboseLevel);
1356 
1357  if (metaCount() > 0) {
1358  os << "Additional metadata:" << std::endl;
1359  for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1360  os << " " << it->first;
1361  if (it->second) {
1362  const std::string value = it->second->str();
1363  if (!value.empty()) os << ": " << value;
1364  }
1365  os << "\n";
1366  }
1367  }
1368 
1369  os << "Transform:" << std::endl;
1370  transform().print(os, /*indent=*/" ");
1371  os << std::endl;
1372 }
1373 
1374 
1376 
1377 
1378 template<typename GridType>
1379 inline typename GridType::Ptr
1380 createGrid(const typename GridType::ValueType& background)
1381 {
1382  return GridType::create(background);
1383 }
1384 
1385 
1386 template<typename GridType>
1387 inline typename GridType::Ptr
1389 {
1390  return GridType::create();
1391 }
1392 
1393 
1394 template<typename TreePtrType>
1397 {
1398  typedef typename TreePtrType::element_type TreeType;
1399  return Grid<TreeType>::create(tree);
1400 }
1401 
1402 
1403 template<typename GridType>
1404 typename GridType::Ptr
1406 {
1407  typedef typename GridType::ValueType ValueType;
1408 
1409  // GridType::ValueType is required to be a floating-point scalar.
1410  BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
1411 
1412  typename GridType::Ptr grid = GridType::create(
1413  /*background=*/static_cast<ValueType>(voxelSize * halfWidth));
1414  grid->setTransform(math::Transform::createLinearTransform(voxelSize));
1415  grid->setGridClass(GRID_LEVEL_SET);
1416  return grid;
1417 }
1418 
1419 } // namespace OPENVDB_VERSION_NAME
1420 } // namespace openvdb
1421 
1422 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
1423 
1424 // Copyright (c) 2012-2016 DreamWorks Animation LLC
1425 // All rights reserved. This software is distributed under the
1426 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:813
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid&#39;s.
boost::shared_ptr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:438
Definition: Types.h:434
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:939
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:426
Base class for typed trees.
Definition: Tree.h:65
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:970
Definition: Types.h:439
static const TreeType & tree(const GridType &g)
Definition: Grid.h:948
virtual void readNonresidentBuffers() const
Read all of this grid&#39;s data buffers that are not yet resident in memory (because delayed loading is ...
Definition: Grid.h:1335
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:594
virtual void clear()
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:589
Grid< typename TreeType::template ValueConverter< OtherValueType >::Type > Type
Definition: Grid.h:514
static const char *const META_GRID_NAME
Definition: Grid.h:281
TreeType::Ptr TreePtrType
Definition: Grid.h:902
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:195
GridClass
Definition: Types.h:211
const TreeType & tree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:762
virtual void readTopology(std::istream &)
Read the grid topology from a stream. This will read only the grid structure, not the actual data buf...
Definition: Grid.h:1301
virtual Name valueType() const
Return the name of the type of a voxel&#39;s value (e.g., "float" or "vec3d").
Definition: Grid.h:579
static TreeType & tree(GridType &g)
Definition: Grid.h:975
TreeType::ValueType ValueType
Definition: Grid.h:940
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:911
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:327
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
const TreeBase & baseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:174
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:634
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:941
static Transform::Ptr createLinearTransform(double voxelSize=1.0)
Create and return a shared pointer to a new transform.
static const TreeType & constTree(GridType &g)
Definition: Grid.h:981
Abstract base class for typed grids.
Definition: Grid.h:103
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:949
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:420
_TreeType TreeType
Definition: Grid.h:488
_TreeType::BuildType BuildType
Definition: Grid.h:492
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:901
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:933
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:603
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:1247
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:145
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:425
boost::shared_ptr< const TreeBase > ConstPtr
Definition: Tree.h:69
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:841
GridType::Ptr GridPtrType
Definition: Grid.h:907
MetadataMap::const_iterator ConstMetaIterator
Definition: MetaMap.h:54
const TreeBase & constBaseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:175
const TreeType & constTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:763
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
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...
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:432
VecType
Definition: Types.h:241
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:963
TreeType::ValueType ValueType
Definition: Grid.h:969
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:912
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:622
std::string Name
Definition: Name.h:44
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:219
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:753
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46
tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:501
static TreeType & tree(GridType &g)
Definition: Grid.h:946
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:934
size_t metaCount() const
Definition: MetaMap.h:118
GridType::Ptr GridPtrType
Definition: Grid.h:937
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:968
virtual Index64 memUsage() const
Definition: Grid.h:742
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:1256
_TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:496
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:965
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:942
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:431
_TreeType::Ptr TreePtrType
Definition: Grid.h:489
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:931
boost::shared_ptr< TreeBase > Ptr
Definition: Tree.h:68
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:629
virtual GridBase::Ptr deepCopyGrid() const
Return a new grid whose metadata, transform and tree are deep copies of this grid&#39;s.
Definition: Grid.h:566
_TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:497
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:513
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:909
Name name
Definition: Grid.h:446
boost::shared_ptr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:423
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1229
static TreeType & tree(TreeType &t)
Definition: Grid.h:945
Grid< TreeType > GridType
Definition: Grid.h:905
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:388
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:352
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:917
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid&#39;s voxels.
Definition: Grid.h:607
boost::shared_ptr< Grid > Ptr
Definition: Grid.h:485
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:983
const ValueType & background() const
Return this grid&#39;s background value.
Definition: Grid.h:584
boost::shared_ptr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:433
Definition: ValueAccessor.h:219
boost::shared_ptr< const Transform > ConstPtr
Definition: Transform.h:70
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:952
math::Transform & transform()
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:335
tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:504
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:288
TreeType & tree()
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:761
virtual CoordBBox evalActiveVoxelBoundingBox() const
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1275
MetaIterator beginMeta()
Definition: MetaMap.h:111
double Real
Definition: Types.h:64
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:398
virtual void setTree(TreeBase::Ptr)
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1174
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:921
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:286
void denseFill(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:1205
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:164
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1050
_TreeType TreeType
Definition: Grid.h:930
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:936
_TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:494
uint64_t Index64
Definition: Types.h:57
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:1032
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1104
#define OPENVDB_VERSION_NAME
Definition: version.h:43
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:943
Vec3< double > Vec3d
Definition: Vec3.h:651
OPENVDB_STATIC_SPECIALIZATION GridType::Ptr clip(const GridType &grid, const BBoxd &)
Clip the given grid against a world-space bounding box and return a new grid containing the result...
Definition: Clip.h:356
virtual Name type() const
Return the name of this grid&#39;s type.
Definition: Grid.h:570
virtual void writeBuffers(std::ostream &) const
Write out all data buffers for this grid.
Definition: Grid.h:1345
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:437
static TreeType & tree(GridType &g)
Definition: Grid.h:916
_TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:495
Calculate an axis-aligned bounding box in index space from a bounding sphere in world space...
Definition: Transform.h:66
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const
Output a human-readable description of this grid.
Definition: Grid.h:1353
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:503
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:898
TreeType::Ptr TreePtrType
Definition: Grid.h:932
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:982
CopyPolicy
Definition: Types.h:434
MergePolicy
Definition: Types.h:264
Definition: Types.h:434
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:328
static const TreeType & constTree(GridType &g)
Definition: Grid.h:950
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
Vec3d voxelSize() const
Return the size of this grid&#39;s voxels.
Definition: Grid.h:347
Definition: Exceptions.h:39
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:938
virtual void writeTopology(std::ostream &) const
Write the grid topology to a stream. This will write only the grid structure, not the actual data buf...
Definition: Grid.h:1309
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:922
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:947
static const char *const META_GRID_CREATOR
Definition: Grid.h:280
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:857
_TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:498
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1396
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:430
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:815
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:623
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid&#39;s voxel at position (x, y, z).
Definition: Grid.h:350
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1267
virtual bool empty() const
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:587
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:463
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:752
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:972
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:1198
boost::shared_ptr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:428
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:903
_TreeType::ValueType ValueType
Definition: Grid.h:491
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:422
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:435
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:904
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:979
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 ...
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:635
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:977
Definition: Exceptions.h:87
void print(std::ostream &os=std::cout, const std::string &indent="") const
Print a description of this transform.
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:421
_TreeType TreeType
Definition: Grid.h:900
static TreeType & tree(TreeType &t)
Definition: Grid.h:974
_TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:499
TreeType::ValueType ValueType
Definition: Grid.h:910
static const TreeType & tree(const GridType &g)
Definition: Grid.h:918
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:906
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid&#39;s transform to the given coordinates.
Definition: Grid.h:356
MetaIterator endMeta()
Definition: MetaMap.h:112
tree::TreeBase TreeBase
Definition: Grid.h:52
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:971
boost::shared_ptr< const Grid > ConstPtr
Definition: Grid.h:486
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:445
virtual void pruneGrid(float tolerance=0.0)
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1212
static TreeType & tree(TreeType &t)
Definition: Grid.h:915
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:1238
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:285
virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy=CP_SHARE) const
Return a new grid of the same type as this grid and whose metadata and transform are deep copies of t...
Definition: Grid.h:1163
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:259
const math::Transform & transform() const
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:336
GridBase(const GridBase &other, ShallowCopy)
Copy another grid&#39;s metadata but share its transform.
Definition: Grid.h:404
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:289
static const TreeType & constTree(GridType &g)
Definition: Grid.h:920
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:287
_TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:490
static const char *const META_GRID_CLASS
Definition: Grid.h:279
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:980
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:390
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:442
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:572
Definition: Exceptions.h:88
virtual void clip(const CoordBBox &)
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1220
Ptr copy(CopyPolicy treePolicy=CP_SHARE) const
Return a new grid of the same type as this grid and whose metadata and transform are deep copies of t...
Definition: Grid.h:1142
virtual void newTree()
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1187
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:502
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:1405
virtual void readBuffers(std::istream &)
Read all data buffers for this grid.
Definition: Grid.h:1317
TreeType & tree() const
Return a reference to the tree associated with this accessor.
Definition: ValueAccessor.h:147
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:427
GridBase(const GridBase &other)
Deep copy another grid&#39;s metadata and transform.
Definition: Grid.h:401
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:883
Grid< TreeType > GridType
Definition: Grid.h:935
static const char *const META_VECTOR_TYPE
Definition: Grid.h:284
Definition: Types.h:213
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:436
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:960
virtual ~Grid()
Definition: Grid.h:552
static const TreeType & tree(const GridType &g)
Definition: Grid.h:978
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:1016
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:919
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:283
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:651
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1039
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:908
virtual Index64 activeVoxelCount() const
Return the number of active voxels.
Definition: Grid.h:734
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:628
virtual ~GridBase()
Definition: Grid.h:112
GridNamePred(const Name &_name)
Definition: Grid.h:444
Definition: Types.h:434
boost::shared_ptr< Transform > Ptr
Definition: Transform.h:69
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:967
virtual TreeBase::ConstPtr constBaseTreePtr() const
Return a pointer to this grid&#39;s tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:754
virtual Coord evalActiveVoxelDim() const
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1285
const math::Transform & constTransform() const
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:337
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:962
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:811
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:913
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:994
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:951
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:282
boost::shared_ptr< MetaMap > Ptr
Definition: MetaMap.h:49
static TreeType & tree(AccessorType &a)
Definition: Grid.h:976