OpenVDB  3.0.0
Grid.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2014 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 
495 
496  typedef typename _TreeType::ValueOnIter ValueOnIter;
497  typedef typename _TreeType::ValueOnCIter ValueOnCIter;
498  typedef typename _TreeType::ValueOffIter ValueOffIter;
499  typedef typename _TreeType::ValueOffCIter ValueOffCIter;
500  typedef typename _TreeType::ValueAllIter ValueAllIter;
501  typedef typename _TreeType::ValueAllCIter ValueAllCIter;
502 
509  template<typename OtherValueType>
510  struct ValueConverter {
512  };
513 
515  static Ptr create(const ValueType& background);
517  static Ptr create();
520  static Ptr create(TreePtrType);
523  static Ptr create(const GridBase& other);
524 
525 
527  Grid();
529  explicit Grid(const ValueType& background);
533  explicit Grid(TreePtrType);
535  Grid(const Grid&);
541  template<typename OtherTreeType>
542  explicit Grid(const Grid<OtherTreeType>&);
544  Grid(const Grid&, ShallowCopy);
547  Grid(const GridBase&);
548 
549  virtual ~Grid() {}
550 
552  Ptr copy(CopyPolicy treePolicy = CP_SHARE) const;
558  virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const;
560 
561  Ptr deepCopy() const { return Ptr(new Grid(*this)); }
563  virtual GridBase::Ptr deepCopyGrid() const { return this->deepCopy(); }
565 
567  virtual Name type() const { return this->gridType(); }
569  static Name gridType() { return TreeType::treeType(); }
570 
571 
572  //
573  // Voxel access methods
574  //
576  virtual Name valueType() const { return tree().valueType(); }
577 
581  const ValueType& background() const { return mTree->background(); }
582 
584  virtual bool empty() const { return tree().empty(); }
586  virtual void clear() { tree().clear(); }
587 
589  Accessor getAccessor() { return Accessor(tree()); }
591  ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
593  ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
595 
597  ValueOnIter beginValueOn() { return tree().beginValueOn(); }
599  ValueOnCIter beginValueOn() const { return tree().cbeginValueOn(); }
600  ValueOnCIter cbeginValueOn() const { return tree().cbeginValueOn(); }
602 
603  ValueOffIter beginValueOff() { return tree().beginValueOff(); }
605  ValueOffCIter beginValueOff() const { return tree().cbeginValueOff(); }
606  ValueOffCIter cbeginValueOff() const { return tree().cbeginValueOff(); }
608 
609  ValueAllIter beginValueAll() { return tree().beginValueAll(); }
611  ValueAllCIter beginValueAll() const { return tree().cbeginValueAll(); }
612  ValueAllCIter cbeginValueAll() const { return tree().cbeginValueAll(); }
614 
616  void evalMinMax(ValueType& minVal, ValueType& maxVal) const;
617 
626  void fill(const CoordBBox& bbox, const ValueType& value, bool active = true);
627 
629  virtual void pruneGrid(float tolerance = 0.0);
630 
631 #ifndef OPENVDB_2_ABI_COMPATIBLE
632  virtual void clip(const CoordBBox&);
637 #endif
638 
644  void merge(Grid& other, MergePolicy policy = MERGE_ACTIVE_STATES);
645 
659  template<typename OtherTreeType>
660  void topologyUnion(const Grid<OtherTreeType>& other);
661 
674  template<typename OtherTreeType>
675  void topologyIntersection(const Grid<OtherTreeType>& other);
676 
687  template<typename OtherTreeType>
688  void topologyDifference(const Grid<OtherTreeType>& other);
689 
690  //
691  // Statistics
692  //
694  virtual Index64 activeVoxelCount() const { return tree().activeVoxelCount(); }
696  virtual CoordBBox evalActiveVoxelBoundingBox() const;
698  virtual Coord evalActiveVoxelDim() const;
699 
702  virtual Index64 memUsage() const { return tree().memUsage(); }
703 
704 
705  //
706  // Tree methods
707  //
709  TreePtrType treePtr() { return mTree; }
712  ConstTreePtrType treePtr() const { return mTree; }
713  ConstTreePtrType constTreePtr() const { return mTree; }
714  virtual TreeBase::ConstPtr constBaseTreePtr() const { return mTree; }
716 
717  TreeType& tree() { return *mTree; }
722  const TreeType& tree() const { return *mTree; }
723  const TreeType& constTree() const { return *mTree; }
725 
731  virtual void setTree(TreeBase::Ptr);
732 
735  virtual void newTree();
736 
737 
738  //
739  // I/O methods
740  //
743  virtual void readTopology(std::istream&);
746  virtual void writeTopology(std::ostream&) const;
747 
749  virtual void readBuffers(std::istream&);
750 #ifndef OPENVDB_2_ABI_COMPATIBLE
751  virtual void readBuffers(std::istream&, const CoordBBox&);
758  virtual void readNonresidentBuffers() const;
759 #endif
760  virtual void writeBuffers(std::ostream&) const;
762 
764  virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const;
765 
766 
767  //
768  // Registry methods
769  //
773  static void registerGrid() { GridBase::registerGrid(Grid::gridType(), Grid::factory); }
776 
777 
778 private:
780  Grid& operator=(const Grid& other);
781 
783  static GridBase::Ptr factory() { return Grid::create(); }
784 
785  TreePtrType mTree;
786 }; // class Grid
787 
788 
790 
791 
799 template<typename GridType>
800 inline typename GridType::Ptr
802 {
803  return GridBase::grid<GridType>(grid);
804 }
805 
806 
815 template<typename GridType>
816 inline typename GridType::ConstPtr
818 {
819  return GridBase::constGrid<GridType>(grid);
820 }
821 
822 
824 
825 
832 template<typename GridType>
833 inline typename GridType::Ptr
835 {
836  if (!grid || !grid->isType<GridType>()) return typename GridType::Ptr();
837  return gridPtrCast<GridType>(grid->deepCopyGrid());
838 }
839 
840 
841 template<typename GridType>
842 inline typename GridType::Ptr
844 {
845  if (!grid.isType<GridType>()) return typename GridType::Ptr();
846  return gridPtrCast<GridType>(grid.deepCopyGrid());
847 }
849 
850 
852 
853 
855 template<typename _TreeType>
859 {
860  typedef _TreeType TreeType;
861  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
862  typedef typename TreeType::Ptr TreePtrType;
863  typedef typename TreeType::ConstPtr ConstTreePtrType;
864  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
867  typedef typename GridType::Ptr GridPtrType;
870  typedef typename TreeType::ValueType ValueType;
874 
875  static TreeType& tree(TreeType& t) { return t; }
876  static TreeType& tree(GridType& g) { return g.tree(); }
877  static const TreeType& tree(const TreeType& t) { return t; }
878  static const TreeType& tree(const GridType& g) { return g.tree(); }
879  static const TreeType& constTree(TreeType& t) { return t; }
880  static const TreeType& constTree(GridType& g) { return g.constTree(); }
881  static const TreeType& constTree(const TreeType& t) { return t; }
882  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
883 };
884 
885 
887 template<typename _TreeType>
888 struct TreeAdapter<Grid<_TreeType> >
889 {
890  typedef _TreeType TreeType;
891  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
892  typedef typename TreeType::Ptr TreePtrType;
893  typedef typename TreeType::ConstPtr ConstTreePtrType;
894  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
897  typedef typename GridType::Ptr GridPtrType;
900  typedef typename TreeType::ValueType ValueType;
904 
905  static TreeType& tree(TreeType& t) { return t; }
906  static TreeType& tree(GridType& g) { return g.tree(); }
907  static const TreeType& tree(const TreeType& t) { return t; }
908  static const TreeType& tree(const GridType& g) { return g.tree(); }
909  static const TreeType& constTree(TreeType& t) { return t; }
910  static const TreeType& constTree(GridType& g) { return g.constTree(); }
911  static const TreeType& constTree(const TreeType& t) { return t; }
912  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
913 };
914 
916 template<typename _TreeType>
917 struct TreeAdapter<tree::ValueAccessor<_TreeType> >
918 {
919  typedef _TreeType TreeType;
920  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
921  typedef typename TreeType::Ptr TreePtrType;
922  typedef typename TreeType::ConstPtr ConstTreePtrType;
923  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
926  typedef typename GridType::Ptr GridPtrType;
929  typedef typename TreeType::ValueType ValueType;
933 
934  static TreeType& tree(TreeType& t) { return t; }
935  static TreeType& tree(GridType& g) { return g.tree(); }
936  static TreeType& tree(AccessorType& a) { return a.tree(); }
937  static const TreeType& tree(const TreeType& t) { return t; }
938  static const TreeType& tree(const GridType& g) { return g.tree(); }
939  static const TreeType& tree(const AccessorType& a) { return a.tree(); }
940  static const TreeType& constTree(TreeType& t) { return t; }
941  static const TreeType& constTree(GridType& g) { return g.constTree(); }
942  static const TreeType& constTree(const TreeType& t) { return t; }
943  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
944 };
945 
947 
948 
950 
951 
952 template<typename GridType>
953 inline typename GridType::Ptr
955 {
956  // The string comparison on type names is slower than a dynamic_pointer_cast, but
957  // it is safer when pointers cross dso boundaries, as they do in many Houdini nodes.
958  if (grid && grid->type() == GridType::gridType()) {
959  return boost::static_pointer_cast<GridType>(grid);
960  }
961  return typename GridType::Ptr();
962 }
963 
964 
965 template<typename GridType>
966 inline typename GridType::ConstPtr
968 {
969  return boost::const_pointer_cast<const GridType>(
970  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
971 }
972 
973 
974 template<typename GridType>
975 inline typename GridType::ConstPtr
977 {
978  return boost::const_pointer_cast<const GridType>(GridBase::grid<GridType>(grid));
979 }
980 
981 
982 template<typename GridType>
983 inline typename GridType::ConstPtr
985 {
986  return boost::const_pointer_cast<const GridType>(
987  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
988 }
989 
990 
991 inline TreeBase::Ptr
993 {
994  return boost::const_pointer_cast<TreeBase>(this->constBaseTreePtr());
995 }
996 
997 
998 inline void
1000 {
1001  if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
1002  mTransform = xform;
1003 }
1004 
1005 
1007 
1008 
1009 template<typename TreeT>
1010 inline Grid<TreeT>::Grid(): mTree(new TreeType)
1011 {
1012 }
1013 
1014 
1015 template<typename TreeT>
1016 inline Grid<TreeT>::Grid(const ValueType &background): mTree(new TreeType(background))
1017 {
1018 }
1019 
1020 
1021 template<typename TreeT>
1022 inline Grid<TreeT>::Grid(TreePtrType tree): mTree(tree)
1023 {
1024  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1025 }
1026 
1027 
1028 template<typename TreeT>
1029 inline Grid<TreeT>::Grid(const Grid& other):
1030  GridBase(other),
1031  mTree(boost::static_pointer_cast<TreeType>(other.mTree->copy()))
1032 {
1033 }
1034 
1035 
1036 template<typename TreeT>
1037 template<typename OtherTreeType>
1039  GridBase(other),
1040  mTree(new TreeType(other.constTree()))
1041 {
1042 }
1043 
1044 
1045 template<typename TreeT>
1046 inline Grid<TreeT>::Grid(const Grid& other, ShallowCopy):
1047  GridBase(other, ShallowCopy()),
1048  mTree(other.mTree)
1049 {
1050 }
1051 
1052 
1053 template<typename TreeT>
1054 inline Grid<TreeT>::Grid(const GridBase& other):
1055  GridBase(other),
1056  mTree(new TreeType)
1057 {
1058 }
1059 
1060 
1061 //static
1062 template<typename TreeT>
1063 inline typename Grid<TreeT>::Ptr
1065 {
1066  return Grid::create(zeroVal<ValueType>());
1067 }
1068 
1069 
1070 //static
1071 template<typename TreeT>
1072 inline typename Grid<TreeT>::Ptr
1073 Grid<TreeT>::create(const ValueType& background)
1074 {
1075  return Ptr(new Grid(background));
1076 }
1077 
1078 
1079 //static
1080 template<typename TreeT>
1081 inline typename Grid<TreeT>::Ptr
1082 Grid<TreeT>::create(TreePtrType tree)
1083 {
1084  return Ptr(new Grid(tree));
1085 }
1086 
1087 
1088 //static
1089 template<typename TreeT>
1090 inline typename Grid<TreeT>::Ptr
1092 {
1093  return Ptr(new Grid(other));
1094 }
1095 
1096 
1098 
1099 
1100 template<typename TreeT>
1101 inline typename Grid<TreeT>::Ptr
1103 {
1104  Ptr ret;
1105  switch (treePolicy) {
1106  case CP_NEW:
1107  ret.reset(new Grid(*this, ShallowCopy()));
1108  ret->newTree();
1109  break;
1110  case CP_COPY:
1111  ret.reset(new Grid(*this));
1112  break;
1113  case CP_SHARE:
1114  ret.reset(new Grid(*this, ShallowCopy()));
1115  break;
1116  }
1117  return ret;
1118 }
1119 
1120 
1121 template<typename TreeT>
1122 inline GridBase::Ptr
1124 {
1125  return this->copy(treePolicy);
1126 }
1127 
1128 
1130 
1131 
1132 template<typename TreeT>
1133 inline void
1135 {
1136  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1137  if (tree->type() != TreeType::treeType()) {
1138  OPENVDB_THROW(TypeError, "Cannot assign a tree of type "
1139  + tree->type() + " to a grid of type " + this->type());
1140  }
1141  mTree = boost::static_pointer_cast<TreeType>(tree);
1142 }
1143 
1144 
1145 template<typename TreeT>
1146 inline void
1148 {
1149  mTree.reset(new TreeType(this->background()));
1150 }
1151 
1152 
1154 
1155 
1156 template<typename TreeT>
1157 inline void
1158 Grid<TreeT>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1159 {
1160  tree().fill(bbox, value, active);
1161 }
1162 
1163 template<typename TreeT>
1164 inline void
1165 Grid<TreeT>::pruneGrid(float tolerance)
1166 {
1167  this->tree().prune(ValueType(zeroVal<ValueType>() + tolerance));
1168 }
1169 
1170 #ifndef OPENVDB_2_ABI_COMPATIBLE
1171 template<typename TreeT>
1172 inline void
1173 Grid<TreeT>::clip(const CoordBBox& bbox)
1174 {
1175  tree().clip(bbox);
1176 }
1177 #endif
1178 
1179 
1180 template<typename TreeT>
1181 inline void
1183 {
1184  tree().merge(other.tree(), policy);
1185 }
1186 
1187 
1188 template<typename TreeT>
1189 template<typename OtherTreeType>
1190 inline void
1192 {
1193  tree().topologyUnion(other.tree());
1194 }
1195 
1196 
1197 template<typename TreeT>
1198 template<typename OtherTreeType>
1199 inline void
1201 {
1202  tree().topologyIntersection(other.tree());
1203 }
1204 
1205 
1206 template<typename TreeT>
1207 template<typename OtherTreeType>
1208 inline void
1210 {
1211  tree().topologyDifference(other.tree());
1212 }
1213 
1214 
1216 
1217 
1218 template<typename TreeT>
1219 inline void
1220 Grid<TreeT>::evalMinMax(ValueType& minVal, ValueType& maxVal) const
1221 {
1222  tree().evalMinMax(minVal, maxVal);
1223 }
1224 
1225 
1226 template<typename TreeT>
1227 inline CoordBBox
1229 {
1230  CoordBBox bbox;
1231  tree().evalActiveVoxelBoundingBox(bbox);
1232  return bbox;
1233 }
1234 
1235 
1236 template<typename TreeT>
1237 inline Coord
1239 {
1240  Coord dim;
1241  const bool nonempty = tree().evalActiveVoxelDim(dim);
1242  return (nonempty ? dim : Coord());
1243 }
1244 
1245 
1247 
1248 
1251 
1252 template<typename TreeT>
1253 inline void
1254 Grid<TreeT>::readTopology(std::istream& is)
1255 {
1256  tree().readTopology(is, saveFloatAsHalf());
1257 }
1258 
1259 
1260 template<typename TreeT>
1261 inline void
1262 Grid<TreeT>::writeTopology(std::ostream& os) const
1263 {
1264  tree().writeTopology(os, saveFloatAsHalf());
1265 }
1266 
1267 
1268 template<typename TreeT>
1269 inline void
1270 Grid<TreeT>::readBuffers(std::istream& is)
1271 {
1272  tree().readBuffers(is, saveFloatAsHalf());
1273 }
1274 
1275 
1276 #ifndef OPENVDB_2_ABI_COMPATIBLE
1277 
1278 template<typename TreeT>
1279 inline void
1280 Grid<TreeT>::readBuffers(std::istream& is, const CoordBBox& bbox)
1281 {
1282  tree().readBuffers(is, bbox, saveFloatAsHalf());
1283 }
1284 
1285 
1286 template<typename TreeT>
1287 inline void
1289 {
1290  tree().readNonresidentBuffers();
1291 }
1292 
1293 #endif // !OPENVDB_2_ABI_COMPATIBLE
1294 
1295 
1296 template<typename TreeT>
1297 inline void
1298 Grid<TreeT>::writeBuffers(std::ostream& os) const
1299 {
1300  tree().writeBuffers(os, saveFloatAsHalf());
1301 }
1302 
1303 
1304 template<typename TreeT>
1305 inline void
1306 Grid<TreeT>::print(std::ostream& os, int verboseLevel) const
1307 {
1308  tree().print(os, verboseLevel);
1309 
1310  if (metaCount() > 0) {
1311  os << "Additional metadata:" << std::endl;
1312  for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1313  os << " " << it->first;
1314  if (it->second) {
1315  const std::string value = it->second->str();
1316  if (!value.empty()) os << ": " << value;
1317  }
1318  os << "\n";
1319  }
1320  }
1321 
1322  os << "Transform:" << std::endl;
1323  transform().print(os, /*indent=*/" ");
1324  os << std::endl;
1325 }
1326 
1327 
1329 
1330 
1331 template<typename GridType>
1332 inline typename GridType::Ptr
1333 createGrid(const typename GridType::ValueType& background)
1334 {
1335  return GridType::create(background);
1336 }
1337 
1338 
1339 template<typename GridType>
1340 inline typename GridType::Ptr
1342 {
1343  return GridType::create();
1344 }
1345 
1346 
1347 template<typename TreePtrType>
1349 createGrid(TreePtrType tree)
1350 {
1351  typedef typename TreePtrType::element_type TreeType;
1352  return Grid<TreeType>::create(tree);
1353 }
1354 
1355 
1356 template<typename GridType>
1357 typename GridType::Ptr
1358 createLevelSet(Real voxelSize, Real halfWidth)
1359 {
1360  typedef typename GridType::ValueType ValueType;
1361 
1362  // GridType::ValueType is required to be a floating-point scalar.
1363  BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
1364 
1365  typename GridType::Ptr grid = GridType::create(
1366  /*background=*/static_cast<ValueType>(voxelSize * halfWidth));
1367  grid->setTransform(math::Transform::createLinearTransform(voxelSize));
1368  grid->setGridClass(GRID_LEVEL_SET);
1369  return grid;
1370 }
1371 
1372 } // namespace OPENVDB_VERSION_NAME
1373 } // namespace openvdb
1374 
1375 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
1376 
1377 // Copyright (c) 2012-2014 DreamWorks Animation LLC
1378 // All rights reserved. This software is distributed under the
1379 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:606
GridNamePred(const Name &_name)
Definition: Grid.h:444
static const TreeType & tree(const GridType &g)
Definition: Grid.h:908
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:899
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:187
_TreeType TreeType
Definition: Grid.h:488
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:388
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:922
TreeType::ValueType ValueType
Definition: Grid.h:900
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:347
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:901
void topologyIntersection(const Grid< OtherTreeType > &other)
Intersect this grid's set of active values with the active values of the other grid, whose value type may be different.
Definition: Grid.h:1200
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:611
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:589
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:909
virtual void clear()
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:586
boost::shared_ptr< const TreeBase > ConstPtr
Definition: Tree.h:67
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:442
Calculate an axis-aligned bounding box in index space from a bounding sphere in world space...
Definition: Transform.h:66
virtual bool empty() const
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:584
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:1254
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:863
static TreeType & tree(AccessorType &a)
Definition: Grid.h:936
std::string Name
Definition: Name.h:44
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:869
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:893
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:864
boost::shared_ptr< Transform > Ptr
Definition: Transform.h:69
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:1123
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:445
virtual Index64 memUsage() const
Definition: Grid.h:702
Abstract base class for typed grids.
Definition: Grid.h:103
uint64_t Index64
Definition: Types.h:58
Grid< TreeType > GridType
Definition: Grid.h:865
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...
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:928
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:581
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:356
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:877
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:722
virtual Name type() const
Return the name of this grid's type.
Definition: Grid.h:567
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:920
Definition: ValueAccessor.h:173
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:1262
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:352
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:283
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1333
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const
Output a human-readable description of this grid.
Definition: Grid.h:1306
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:420
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
tree::ValueAccessor< const _TreeType > ConstAccessor
Definition: Grid.h:494
void topologyDifference(const Grid< OtherTreeType > &other)
Difference this grid's set of active values with the active values of the other grid, whose value type may be different.
Definition: Grid.h:1209
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
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
boost::shared_ptr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:423
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:437
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46
static TreeType & tree(GridType &g)
Definition: Grid.h:906
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1220
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:894
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:425
GridType::Ptr GridPtrType
Definition: Grid.h:897
_TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:499
_TreeType TreeType
Definition: Grid.h:860
static const TreeType & constTree(GridType &g)
Definition: Grid.h:880
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:902
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:871
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:866
CopyPolicy
Definition: Types.h:416
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
boost::shared_ptr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:433
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:282
boost::shared_ptr< const Transform > ConstPtr
Definition: Transform.h:70
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:891
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:923
TreeType::ValueType ValueType
Definition: Grid.h:929
double Real
Definition: Types.h:65
static TreeType & tree(TreeType &t)
Definition: Grid.h:905
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
_TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:498
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:930
_TreeType::Ptr TreePtrType
Definition: Grid.h:489
boost::shared_ptr< TreeBase > Ptr
Definition: Tree.h:66
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:721
ConstTreePtrType constTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:713
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:328
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:350
virtual TreeBase::ConstPtr constBaseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:714
TreeBase::Ptr baseTreePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:992
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:912
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:431
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1182
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:872
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1010
Definition: Types.h:416
Name name
Definition: Grid.h:446
boost::shared_ptr< Grid > Ptr
Definition: Grid.h:485
virtual void readNonresidentBuffers() const
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
Definition: Grid.h:1288
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1064
virtual Index64 activeVoxelCount() const
Return the number of active voxels.
Definition: Grid.h:694
Definition: Types.h:210
_TreeType TreeType
Definition: Grid.h:890
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:931
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:896
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:337
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:390
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:879
boost::shared_ptr< MetaMap > Ptr
Definition: MetaMap.h:49
virtual void setTree(TreeBase::Ptr)
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1134
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:903
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:942
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:943
Definition: Types.h:421
ConstTreePtrType treePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:712
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:612
#define OPENVDB_VERSION_NAME
Definition: version.h:43
_TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:497
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 ...
_TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:496
static const char *const META_GRID_CREATOR
Definition: Grid.h:280
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:216
Definition: Exceptions.h:87
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1349
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:430
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:593
static const TreeType & tree(const GridType &g)
Definition: Grid.h:878
virtual void writeBuffers(std::ostream &) const
Write out all data buffers for this grid.
Definition: Grid.h:1298
TreeType::Ptr TreePtrType
Definition: Grid.h:892
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:932
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:925
_TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:500
boost::shared_ptr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:428
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:775
static const TreeType & constTree(GridType &g)
Definition: Grid.h:910
static TreeType & tree(TreeType &t)
Definition: Grid.h:875
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:898
Definition: Exceptions.h:39
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:907
virtual Name valueType() const
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:576
virtual Coord evalActiveVoxelDim() const
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1238
virtual GridBase::Ptr deepCopyGrid() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:563
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:937
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:421
static const TreeType & tree(const GridType &g)
Definition: Grid.h:938
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:336
Vec3< double > Vec3d
Definition: Vec3.h:629
virtual ~GridBase()
Definition: Grid.h:112
_TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:501
MergePolicy
Definition: Types.h:261
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:364
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:285
static Transform::Ptr createLinearTransform(double voxelSize=1.0)
Create and return a shared pointer to a new transform.
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:861
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:288
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:927
boost::shared_ptr< const Grid > ConstPtr
Definition: Grid.h:486
GridBase(const GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:404
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:398
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:286
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:817
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:801
void topologyUnion(const Grid< OtherTreeType > &other)
Union this grid's set of active values with the active values of the other grid, whose value type may...
Definition: Grid.h:1191
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:287
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:1102
static TreeType & tree(GridType &g)
Definition: Grid.h:876
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:954
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:940
tree::ValueAccessor< _TreeType > Accessor
Definition: Grid.h:493
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:600
_TreeType::ValueType ValueType
Definition: Grid.h:491
Definition: Exceptions.h:88
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:723
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:175
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:1358
boost::shared_ptr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:438
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:868
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:426
_TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:490
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:427
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:569
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:401
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:599
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:422
GridClass
Definition: Types.h:208
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:174
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:435
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:882
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:436
virtual void pruneGrid(float tolerance=0.0)
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1165
static TreeType & tree(TreeType &t)
Definition: Grid.h:934
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:873
tree::TreeBase TreeBase
Definition: Grid.h:52
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:999
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:327
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:858
virtual ~Grid()
Definition: Grid.h:549
Definition: Types.h:416
MetadataMap::const_iterator ConstMetaIterator
Definition: MetaMap.h:54
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:1158
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:881
TreeType::Ptr TreePtrType
Definition: Grid.h:862
virtual void clip(const CoordBBox &)
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1173
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:289
virtual void newTree()
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1147
virtual void readBuffers(std::istream &)
Read all data buffers for this grid.
Definition: Grid.h:1270
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
TreeType::ValueType ValueType
Definition: Grid.h:870
Grid< TreeType > GridType
Definition: Grid.h:895
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:432
static const char *const META_GRID_CLASS
Definition: Grid.h:279
virtual CoordBBox evalActiveVoxelBoundingBox() const
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1228
VecType
Definition: Types.h:238
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:771
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:145
Base class for typed trees.
Definition: Tree.h:63
GridType::Ptr deepCopyTypedGrid(const GridBase &grid)
Return a pointer to a deep copy of the given grid, provided that the grid's concrete type is GridType...
Definition: Grid.h:843
static const char *const META_GRID_NAME
Definition: Grid.h:281
TreeBase::ConstPtr baseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:164
static TreeType & tree(GridType &g)
Definition: Grid.h:935
GridType::Ptr GridPtrType
Definition: Grid.h:867
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:773
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:939
static const char *const META_VECTOR_TYPE
Definition: Grid.h:284
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:605
Grid< typename TreeType::template ValueConverter< OtherValueType >::Type > Type
Definition: Grid.h:511
TreeType & tree() const
Return a reference to the tree associated with this accessor.
Definition: ValueAccessor.h:117
ValueConverter::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:510
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:976
static const TreeType & constTree(GridType &g)
Definition: Grid.h:941
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:911
Definition: Types.h:416