OpenVDB  3.1.0
Grid.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2015 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 
493  typedef typename _TreeType::ValueOnIter ValueOnIter;
494  typedef typename _TreeType::ValueOnCIter ValueOnCIter;
495  typedef typename _TreeType::ValueOffIter ValueOffIter;
496  typedef typename _TreeType::ValueOffCIter ValueOffCIter;
497  typedef typename _TreeType::ValueAllIter ValueAllIter;
498  typedef typename _TreeType::ValueAllCIter ValueAllCIter;
499 
504 
511  template<typename OtherValueType>
512  struct ValueConverter {
514  };
515 
517  static Ptr create(const ValueType& background);
519  static Ptr create();
522  static Ptr create(TreePtrType);
525  static Ptr create(const GridBase& other);
526 
527 
529  Grid();
531  explicit Grid(const ValueType& background);
535  explicit Grid(TreePtrType);
537  Grid(const Grid&);
543  template<typename OtherTreeType>
544  explicit Grid(const Grid<OtherTreeType>&);
546  Grid(const Grid&, ShallowCopy);
549  Grid(const GridBase&);
550 
551  virtual ~Grid() {}
552 
554  Ptr copy(CopyPolicy treePolicy = CP_SHARE) const;
560  virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const;
562 
563  Ptr deepCopy() const { return Ptr(new Grid(*this)); }
565  virtual GridBase::Ptr deepCopyGrid() const { return this->deepCopy(); }
567 
569  virtual Name type() const { return this->gridType(); }
571  static Name gridType() { return TreeType::treeType(); }
572 
573 
574  //
575  // Voxel access methods
576  //
578  virtual Name valueType() const { return tree().valueType(); }
579 
583  const ValueType& background() const { return mTree->background(); }
584 
586  virtual bool empty() const { return tree().empty(); }
588  virtual void clear() { tree().clear(); }
589 
593  Accessor getAccessor() { return Accessor(tree()); }
602  Accessor getUnsafeAccessor() { return UnsafeAccessor(tree()); }
604  ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
606  ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
608  ConstAccessor getConstUnsafeAccessor() const { return ConstUnsafeAccessor(tree()); }
617 
619  ValueOnIter beginValueOn() { return tree().beginValueOn(); }
621  ValueOnCIter beginValueOn() const { return tree().cbeginValueOn(); }
622  ValueOnCIter cbeginValueOn() const { return tree().cbeginValueOn(); }
624 
625  ValueOffIter beginValueOff() { return tree().beginValueOff(); }
627  ValueOffCIter beginValueOff() const { return tree().cbeginValueOff(); }
628  ValueOffCIter cbeginValueOff() const { return tree().cbeginValueOff(); }
630 
631  ValueAllIter beginValueAll() { return tree().beginValueAll(); }
633  ValueAllCIter beginValueAll() const { return tree().cbeginValueAll(); }
634  ValueAllCIter cbeginValueAll() const { return tree().cbeginValueAll(); }
636 
638  void evalMinMax(ValueType& minVal, ValueType& maxVal) const;
639 
648  void fill(const CoordBBox& bbox, const ValueType& value, bool active = true);
649 
651  virtual void pruneGrid(float tolerance = 0.0);
652 
653 #ifndef OPENVDB_2_ABI_COMPATIBLE
654  virtual void clip(const CoordBBox&);
659 #endif
660 
666  void merge(Grid& other, MergePolicy policy = MERGE_ACTIVE_STATES);
667 
681  template<typename OtherTreeType>
682  void topologyUnion(const Grid<OtherTreeType>& other);
683 
696  template<typename OtherTreeType>
697  void topologyIntersection(const Grid<OtherTreeType>& other);
698 
709  template<typename OtherTreeType>
710  void topologyDifference(const Grid<OtherTreeType>& other);
711 
712  //
713  // Statistics
714  //
716  virtual Index64 activeVoxelCount() const { return tree().activeVoxelCount(); }
718  virtual CoordBBox evalActiveVoxelBoundingBox() const;
720  virtual Coord evalActiveVoxelDim() const;
721 
724  virtual Index64 memUsage() const { return tree().memUsage(); }
725 
726 
727  //
728  // Tree methods
729  //
731  TreePtrType treePtr() { return mTree; }
734  ConstTreePtrType treePtr() const { return mTree; }
735  ConstTreePtrType constTreePtr() const { return mTree; }
736  virtual TreeBase::ConstPtr constBaseTreePtr() const { return mTree; }
738 
739  TreeType& tree() { return *mTree; }
744  const TreeType& tree() const { return *mTree; }
745  const TreeType& constTree() const { return *mTree; }
747 
753  virtual void setTree(TreeBase::Ptr);
754 
757  virtual void newTree();
758 
759 
760  //
761  // I/O methods
762  //
765  virtual void readTopology(std::istream&);
768  virtual void writeTopology(std::ostream&) const;
769 
771  virtual void readBuffers(std::istream&);
772 #ifndef OPENVDB_2_ABI_COMPATIBLE
773  virtual void readBuffers(std::istream&, const CoordBBox&);
780  virtual void readNonresidentBuffers() const;
781 #endif
782  virtual void writeBuffers(std::ostream&) const;
784 
786  virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const;
787 
788 
789  //
790  // Registry methods
791  //
795  static void registerGrid() { GridBase::registerGrid(Grid::gridType(), Grid::factory); }
798 
799 
800 private:
802  Grid& operator=(const Grid& other);
803 
805  static GridBase::Ptr factory() { return Grid::create(); }
806 
807  TreePtrType mTree;
808 }; // class Grid
809 
810 
812 
813 
821 template<typename GridType>
822 inline typename GridType::Ptr
824 {
825  return GridBase::grid<GridType>(grid);
826 }
827 
828 
837 template<typename GridType>
838 inline typename GridType::ConstPtr
840 {
841  return GridBase::constGrid<GridType>(grid);
842 }
843 
844 
846 
847 
854 template<typename GridType>
855 inline typename GridType::Ptr
857 {
858  if (!grid || !grid->isType<GridType>()) return typename GridType::Ptr();
859  return gridPtrCast<GridType>(grid->deepCopyGrid());
860 }
861 
862 
863 template<typename GridType>
864 inline typename GridType::Ptr
866 {
867  if (!grid.isType<GridType>()) return typename GridType::Ptr();
868  return gridPtrCast<GridType>(grid.deepCopyGrid());
869 }
871 
872 
874 
875 
877 template<typename _TreeType>
881 {
882  typedef _TreeType TreeType;
883  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
884  typedef typename TreeType::Ptr TreePtrType;
885  typedef typename TreeType::ConstPtr ConstTreePtrType;
886  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
889  typedef typename GridType::Ptr GridPtrType;
892  typedef typename TreeType::ValueType ValueType;
896 
897  static TreeType& tree(TreeType& t) { return t; }
898  static TreeType& tree(GridType& g) { return g.tree(); }
899  static const TreeType& tree(const TreeType& t) { return t; }
900  static const TreeType& tree(const GridType& g) { return g.tree(); }
901  static const TreeType& constTree(TreeType& t) { return t; }
902  static const TreeType& constTree(GridType& g) { return g.constTree(); }
903  static const TreeType& constTree(const TreeType& t) { return t; }
904  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
905 };
906 
907 
909 template<typename _TreeType>
910 struct TreeAdapter<Grid<_TreeType> >
911 {
912  typedef _TreeType TreeType;
913  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
914  typedef typename TreeType::Ptr TreePtrType;
915  typedef typename TreeType::ConstPtr ConstTreePtrType;
916  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
919  typedef typename GridType::Ptr GridPtrType;
922  typedef typename TreeType::ValueType ValueType;
926 
927  static TreeType& tree(TreeType& t) { return t; }
928  static TreeType& tree(GridType& g) { return g.tree(); }
929  static const TreeType& tree(const TreeType& t) { return t; }
930  static const TreeType& tree(const GridType& g) { return g.tree(); }
931  static const TreeType& constTree(TreeType& t) { return t; }
932  static const TreeType& constTree(GridType& g) { return g.constTree(); }
933  static const TreeType& constTree(const TreeType& t) { return t; }
934  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
935 };
936 
938 template<typename _TreeType>
939 struct TreeAdapter<tree::ValueAccessor<_TreeType> >
940 {
941  typedef _TreeType TreeType;
942  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
943  typedef typename TreeType::Ptr TreePtrType;
944  typedef typename TreeType::ConstPtr ConstTreePtrType;
945  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
948  typedef typename GridType::Ptr GridPtrType;
951  typedef typename TreeType::ValueType ValueType;
955 
956  static TreeType& tree(TreeType& t) { return t; }
957  static TreeType& tree(GridType& g) { return g.tree(); }
958  static TreeType& tree(AccessorType& a) { return a.tree(); }
959  static const TreeType& tree(const TreeType& t) { return t; }
960  static const TreeType& tree(const GridType& g) { return g.tree(); }
961  static const TreeType& tree(const AccessorType& a) { return a.tree(); }
962  static const TreeType& constTree(TreeType& t) { return t; }
963  static const TreeType& constTree(GridType& g) { return g.constTree(); }
964  static const TreeType& constTree(const TreeType& t) { return t; }
965  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
966 };
967 
969 
970 
972 
973 
974 template<typename GridType>
975 inline typename GridType::Ptr
977 {
978  // The string comparison on type names is slower than a dynamic_pointer_cast, but
979  // it is safer when pointers cross dso boundaries, as they do in many Houdini nodes.
980  if (grid && grid->type() == GridType::gridType()) {
981  return boost::static_pointer_cast<GridType>(grid);
982  }
983  return typename GridType::Ptr();
984 }
985 
986 
987 template<typename GridType>
988 inline typename GridType::ConstPtr
990 {
991  return boost::const_pointer_cast<const GridType>(
992  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
993 }
994 
995 
996 template<typename GridType>
997 inline typename GridType::ConstPtr
999 {
1000  return boost::const_pointer_cast<const GridType>(GridBase::grid<GridType>(grid));
1001 }
1002 
1003 
1004 template<typename GridType>
1005 inline typename GridType::ConstPtr
1007 {
1008  return boost::const_pointer_cast<const GridType>(
1009  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
1010 }
1011 
1012 
1013 inline TreeBase::Ptr
1015 {
1016  return boost::const_pointer_cast<TreeBase>(this->constBaseTreePtr());
1017 }
1018 
1019 
1020 inline void
1022 {
1023  if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
1024  mTransform = xform;
1025 }
1026 
1027 
1029 
1030 
1031 template<typename TreeT>
1032 inline Grid<TreeT>::Grid(): mTree(new TreeType)
1033 {
1034 }
1035 
1036 
1037 template<typename TreeT>
1038 inline Grid<TreeT>::Grid(const ValueType &background): mTree(new TreeType(background))
1039 {
1040 }
1041 
1042 
1043 template<typename TreeT>
1044 inline Grid<TreeT>::Grid(TreePtrType tree): mTree(tree)
1045 {
1046  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1047 }
1048 
1049 
1050 template<typename TreeT>
1051 inline Grid<TreeT>::Grid(const Grid& other):
1052  GridBase(other),
1053  mTree(boost::static_pointer_cast<TreeType>(other.mTree->copy()))
1054 {
1055 }
1056 
1057 
1058 template<typename TreeT>
1059 template<typename OtherTreeType>
1061  GridBase(other),
1062  mTree(new TreeType(other.constTree()))
1063 {
1064 }
1065 
1066 
1067 template<typename TreeT>
1068 inline Grid<TreeT>::Grid(const Grid& other, ShallowCopy):
1069  GridBase(other, ShallowCopy()),
1070  mTree(other.mTree)
1071 {
1072 }
1073 
1074 
1075 template<typename TreeT>
1076 inline Grid<TreeT>::Grid(const GridBase& other):
1077  GridBase(other),
1078  mTree(new TreeType)
1079 {
1080 }
1081 
1082 
1083 //static
1084 template<typename TreeT>
1085 inline typename Grid<TreeT>::Ptr
1087 {
1088  return Grid::create(zeroVal<ValueType>());
1089 }
1090 
1091 
1092 //static
1093 template<typename TreeT>
1094 inline typename Grid<TreeT>::Ptr
1096 {
1097  return Ptr(new Grid(background));
1098 }
1099 
1100 
1101 //static
1102 template<typename TreeT>
1103 inline typename Grid<TreeT>::Ptr
1105 {
1106  return Ptr(new Grid(tree));
1107 }
1108 
1109 
1110 //static
1111 template<typename TreeT>
1112 inline typename Grid<TreeT>::Ptr
1114 {
1115  return Ptr(new Grid(other));
1116 }
1117 
1118 
1120 
1121 
1122 template<typename TreeT>
1123 inline typename Grid<TreeT>::Ptr
1125 {
1126  Ptr ret;
1127  switch (treePolicy) {
1128  case CP_NEW:
1129  ret.reset(new Grid(*this, ShallowCopy()));
1130  ret->newTree();
1131  break;
1132  case CP_COPY:
1133  ret.reset(new Grid(*this));
1134  break;
1135  case CP_SHARE:
1136  ret.reset(new Grid(*this, ShallowCopy()));
1137  break;
1138  }
1139  return ret;
1140 }
1141 
1142 
1143 template<typename TreeT>
1144 inline GridBase::Ptr
1146 {
1147  return this->copy(treePolicy);
1148 }
1149 
1150 
1152 
1153 
1154 template<typename TreeT>
1155 inline void
1157 {
1158  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1159  if (tree->type() != TreeType::treeType()) {
1160  OPENVDB_THROW(TypeError, "Cannot assign a tree of type "
1161  + tree->type() + " to a grid of type " + this->type());
1162  }
1163  mTree = boost::static_pointer_cast<TreeType>(tree);
1164 }
1165 
1166 
1167 template<typename TreeT>
1168 inline void
1170 {
1171  mTree.reset(new TreeType(this->background()));
1172 }
1173 
1174 
1176 
1177 
1178 template<typename TreeT>
1179 inline void
1180 Grid<TreeT>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1181 {
1182  tree().fill(bbox, value, active);
1183 }
1184 
1185 template<typename TreeT>
1186 inline void
1187 Grid<TreeT>::pruneGrid(float tolerance)
1188 {
1189  this->tree().prune(ValueType(zeroVal<ValueType>() + tolerance));
1190 }
1191 
1192 #ifndef OPENVDB_2_ABI_COMPATIBLE
1193 template<typename TreeT>
1194 inline void
1195 Grid<TreeT>::clip(const CoordBBox& bbox)
1196 {
1197  tree().clip(bbox);
1198 }
1199 #endif
1200 
1201 
1202 template<typename TreeT>
1203 inline void
1205 {
1206  tree().merge(other.tree(), policy);
1207 }
1208 
1209 
1210 template<typename TreeT>
1211 template<typename OtherTreeType>
1212 inline void
1214 {
1215  tree().topologyUnion(other.tree());
1216 }
1217 
1218 
1219 template<typename TreeT>
1220 template<typename OtherTreeType>
1221 inline void
1223 {
1224  tree().topologyIntersection(other.tree());
1225 }
1226 
1227 
1228 template<typename TreeT>
1229 template<typename OtherTreeType>
1230 inline void
1232 {
1233  tree().topologyDifference(other.tree());
1234 }
1235 
1236 
1238 
1239 
1240 template<typename TreeT>
1241 inline void
1243 {
1244  tree().evalMinMax(minVal, maxVal);
1245 }
1246 
1247 
1248 template<typename TreeT>
1249 inline CoordBBox
1251 {
1252  CoordBBox bbox;
1253  tree().evalActiveVoxelBoundingBox(bbox);
1254  return bbox;
1255 }
1256 
1257 
1258 template<typename TreeT>
1259 inline Coord
1261 {
1262  Coord dim;
1263  const bool nonempty = tree().evalActiveVoxelDim(dim);
1264  return (nonempty ? dim : Coord());
1265 }
1266 
1267 
1269 
1270 
1273 
1274 template<typename TreeT>
1275 inline void
1276 Grid<TreeT>::readTopology(std::istream& is)
1277 {
1278  tree().readTopology(is, saveFloatAsHalf());
1279 }
1280 
1281 
1282 template<typename TreeT>
1283 inline void
1284 Grid<TreeT>::writeTopology(std::ostream& os) const
1285 {
1286  tree().writeTopology(os, saveFloatAsHalf());
1287 }
1288 
1289 
1290 template<typename TreeT>
1291 inline void
1292 Grid<TreeT>::readBuffers(std::istream& is)
1293 {
1294  tree().readBuffers(is, saveFloatAsHalf());
1295 }
1296 
1297 
1298 #ifndef OPENVDB_2_ABI_COMPATIBLE
1299 
1300 template<typename TreeT>
1301 inline void
1302 Grid<TreeT>::readBuffers(std::istream& is, const CoordBBox& bbox)
1303 {
1304  tree().readBuffers(is, bbox, saveFloatAsHalf());
1305 }
1306 
1307 
1308 template<typename TreeT>
1309 inline void
1311 {
1312  tree().readNonresidentBuffers();
1313 }
1314 
1315 #endif // !OPENVDB_2_ABI_COMPATIBLE
1316 
1317 
1318 template<typename TreeT>
1319 inline void
1320 Grid<TreeT>::writeBuffers(std::ostream& os) const
1321 {
1322  tree().writeBuffers(os, saveFloatAsHalf());
1323 }
1324 
1325 
1326 template<typename TreeT>
1327 inline void
1328 Grid<TreeT>::print(std::ostream& os, int verboseLevel) const
1329 {
1330  tree().print(os, verboseLevel);
1331 
1332  if (metaCount() > 0) {
1333  os << "Additional metadata:" << std::endl;
1334  for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1335  os << " " << it->first;
1336  if (it->second) {
1337  const std::string value = it->second->str();
1338  if (!value.empty()) os << ": " << value;
1339  }
1340  os << "\n";
1341  }
1342  }
1343 
1344  os << "Transform:" << std::endl;
1345  transform().print(os, /*indent=*/" ");
1346  os << std::endl;
1347 }
1348 
1349 
1351 
1352 
1353 template<typename GridType>
1354 inline typename GridType::Ptr
1355 createGrid(const typename GridType::ValueType& background)
1356 {
1357  return GridType::create(background);
1358 }
1359 
1360 
1361 template<typename GridType>
1362 inline typename GridType::Ptr
1364 {
1365  return GridType::create();
1366 }
1367 
1368 
1369 template<typename TreePtrType>
1372 {
1373  typedef typename TreePtrType::element_type TreeType;
1374  return Grid<TreeType>::create(tree);
1375 }
1376 
1377 
1378 template<typename GridType>
1379 typename GridType::Ptr
1381 {
1382  typedef typename GridType::ValueType ValueType;
1383 
1384  // GridType::ValueType is required to be a floating-point scalar.
1385  BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
1386 
1387  typename GridType::Ptr grid = GridType::create(
1388  /*background=*/static_cast<ValueType>(voxelSize * halfWidth));
1389  grid->setTransform(math::Transform::createLinearTransform(voxelSize));
1390  grid->setGridClass(GRID_LEVEL_SET);
1391  return grid;
1392 }
1393 
1394 } // namespace OPENVDB_VERSION_NAME
1395 } // namespace openvdb
1396 
1397 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
1398 
1399 // Copyright (c) 2012-2015 DreamWorks Animation LLC
1400 // All rights reserved. This software is distributed under the
1401 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
static const TreeType & tree(const GridType &g)
Definition: Grid.h:930
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:839
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:893
_TreeType TreeType
Definition: Grid.h:488
static TreeType & tree(GridType &g)
Definition: Grid.h:957
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:895
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:921
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:961
static TreeType & tree(AccessorType &a)
Definition: Grid.h:958
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:195
static TreeType & tree(TreeType &t)
Definition: Grid.h:956
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:633
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:593
virtual void clear()
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:588
boost::shared_ptr< const TreeBase > ConstPtr
Definition: Tree.h:67
TreeType::ValueType ValueType
Definition: Grid.h:922
MetadataMap::const_iterator ConstMetaIterator
Definition: MetaMap.h:54
Definition: Types.h:411
virtual bool empty() const
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:586
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:1276
const TreeBase & constBaseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:175
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:923
TreeType::Ptr TreePtrType
Definition: Grid.h:884
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:1380
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:944
boost::shared_ptr< MetaMap > Ptr
Definition: MetaMap.h:49
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:931
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:1222
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:427
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:915
virtual Index64 memUsage() const
Definition: Grid.h:724
Abstract base class for typed grids.
Definition: Grid.h:103
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:950
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:823
const ValueType & background() const
Return this grid&#39;s background value.
Definition: Grid.h:583
static const char *const META_GRID_CREATOR
Definition: Grid.h:280
const TreeType & tree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:744
tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:500
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:952
Name name
Definition: Grid.h:446
Definition: Exceptions.h:88
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:1145
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
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:1231
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:145
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
MergePolicy
Definition: Types.h:257
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1242
virtual Name type() const
Return the name of this grid&#39;s type.
Definition: Grid.h:569
TreeType & tree() const
Return a reference to the tree associated with this accessor.
Definition: ValueAccessor.h:147
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:1284
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
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const
Output a human-readable description of this grid.
Definition: Grid.h:1328
static TreeType & tree(GridType &g)
Definition: Grid.h:928
Vec3d voxelSize() const
Return the size of this grid&#39;s voxels.
Definition: Grid.h:347
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:436
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:355
static const char *const META_GRID_CLASS
Definition: Grid.h:279
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:924
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:916
GridType::Ptr GridPtrType
Definition: Grid.h:919
_TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:496
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:390
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:913
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:964
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:285
boost::shared_ptr< TreeBase > Ptr
Definition: Tree.h:66
TreeType & tree()
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:743
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:422
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:735
MetaIterator beginMeta()
Definition: MetaMap.h:111
const TreeBase & baseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:174
static TreeType & tree(TreeType &t)
Definition: Grid.h:927
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:945
GridBase(const GridBase &other, ShallowCopy)
Copy another grid&#39;s metadata but share its transform.
Definition: Grid.h:404
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:435
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:289
static const char *const META_VECTOR_TYPE
Definition: Grid.h:284
_TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:495
_TreeType::Ptr TreePtrType
Definition: Grid.h:489
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:287
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:998
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
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:283
tree::TreeBase TreeBase
Definition: Grid.h:52
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1032
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:904
GridType::Ptr GridPtrType
Definition: Grid.h:889
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:736
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:934
Base class for typed trees.
Definition: Tree.h:63
boost::shared_ptr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:438
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:426
boost::shared_ptr< Grid > Ptr
Definition: Grid.h:485
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:1310
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1204
GridBase(const GridBase &other)
Deep copy another grid&#39;s metadata and transform.
Definition: Grid.h:401
GridClass
Definition: Types.h:204
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
_TreeType TreeType
Definition: Grid.h:912
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:734
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1086
virtual Index64 activeVoxelCount() const
Return the number of active voxels.
Definition: Grid.h:716
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:918
tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:503
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:925
TreeType::ValueType ValueType
Definition: Grid.h:951
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1021
_TreeType TreeType
Definition: Grid.h:882
#define OPENVDB_VERSION_NAME
Definition: version.h:43
_TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:493
virtual void setTree(TreeBase::Ptr)
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1156
static TreeType & tree(GridType &g)
Definition: Grid.h:898
virtual ~GridBase()
Definition: Grid.h:112
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:888
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid&#39;s voxels.
Definition: Grid.h:606
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:634
_TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:494
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
tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:502
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:891
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:432
TreeType::Ptr TreePtrType
Definition: Grid.h:914
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:976
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:962
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:442
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:282
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:512
boost::shared_ptr< Transform > Ptr
Definition: Transform.h:69
VecType
Definition: Types.h:234
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...
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:352
virtual void writeBuffers(std::ostream &) const
Write out all data buffers for this grid.
Definition: Grid.h:1320
virtual Name valueType() const
Return the name of the type of a voxel&#39;s value (e.g., "float" or "vec3d").
Definition: Grid.h:578
virtual Coord evalActiveVoxelDim() const
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1260
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:565
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
Grid< TreeType > GridType
Definition: Grid.h:887
static const TreeType & constTree(GridType &g)
Definition: Grid.h:932
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid&#39;s.
std::string Name
Definition: Name.h:44
_TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:497
Definition: Exceptions.h:39
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:899
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:797
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:920
static const char *const META_GRID_NAME
Definition: Grid.h:281
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:953
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:929
Accessor 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:602
Definition: Types.h:411
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:954
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:947
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:880
boost::shared_ptr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:433
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:903
MetaIterator endMeta()
Definition: MetaMap.h:112
Vec3< double > Vec3d
Definition: Vec3.h:643
Definition: Types.h:206
boost::shared_ptr< const Grid > ConstPtr
Definition: Grid.h:486
TreeType::ValueType ValueType
Definition: Grid.h:892
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:959
boost::shared_ptr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:423
_TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:498
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:622
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
void print(std::ostream &os=std::cout, const std::string &indent="") const
Print a description of this transform.
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:965
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
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:1213
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:1124
size_t metaCount() const
Definition: MetaMap.h:118
_TreeType::ValueType ValueType
Definition: Grid.h:491
const TreeType & constTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:745
Calculate an axis-aligned bounding box in index space from a bounding sphere in world space...
Definition: Transform.h:66
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:420
double Real
Definition: Types.h:64
virtual void pruneGrid(float tolerance=0.0)
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1187
static const TreeType & tree(const GridType &g)
Definition: Grid.h:960
_TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:490
Definition: ValueAccessor.h:219
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:571
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:425
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:621
static TreeType & tree(TreeType &t)
Definition: Grid.h:897
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:388
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid&#39;s voxel at position (x, y, z).
Definition: Grid.h:350
uint64_t Index64
Definition: Types.h:57
CopyPolicy
Definition: Types.h:411
Definition: Types.h:416
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:288
static const TreeType & constTree(GridType &g)
Definition: Grid.h:902
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:1180
virtual void clip(const CoordBBox &)
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1195
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:398
virtual void newTree()
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1169
tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:501
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:901
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:286
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1371
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:430
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:437
virtual ~Grid()
Definition: Grid.h:551
static Transform::Ptr createLinearTransform(double voxelSize=1.0)
Create and return a shared pointer to a new transform.
Grid< TreeType > GridType
Definition: Grid.h:917
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:885
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:883
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:793
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:1014
virtual void readBuffers(std::istream &)
Read all data buffers for this grid.
Definition: Grid.h:1292
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 ...
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:886
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:431
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:865
boost::shared_ptr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:428
Definition: Exceptions.h:87
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:942
math::Transform & transform()
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:335
virtual CoordBBox evalActiveVoxelBoundingBox() const
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1250
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:949
static const TreeType & tree(const GridType &g)
Definition: Grid.h:900
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:795
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:421
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:627
boost::shared_ptr< const Transform > ConstPtr
Definition: Transform.h:70
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:212
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:890
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:894
static const TreeType & constTree(GridType &g)
Definition: Grid.h:963
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
Definition: Types.h:411
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:445
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:628
GridNamePred(const Name &_name)
Definition: Grid.h:444
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:933
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid&#39;s transform to the given coordinates.
Definition: Grid.h:356
Grid< typename TreeType::template ValueConverter< OtherValueType >::Type > Type
Definition: Grid.h:513