OpenVDB  2.0.0
Grid.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 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 
201  //
202  // Metadata
203  //
205  std::string getName() const;
207  void setName(const std::string&);
208 
210  std::string getCreator() const;
212  void setCreator(const std::string&);
213 
216  bool saveFloatAsHalf() const;
217  void setSaveFloatAsHalf(bool);
218 
220  GridClass getGridClass() const;
222  void setGridClass(GridClass);
224  void clearGridClass();
225 
227  static std::string gridClassToString(GridClass);
229  static std::string gridClassToMenuName(GridClass);
233  static GridClass stringToGridClass(const std::string&);
234 
237  VecType getVectorType() const;
240  void setVectorType(VecType);
242  void clearVectorType();
243 
245  static std::string vecTypeToString(VecType);
248  static std::string vecTypeExamples(VecType);
251  static std::string vecTypeDescription(VecType);
252  static VecType stringToVecType(const std::string&);
253 
257  bool isInWorldSpace() const;
259  void setIsInWorldSpace(bool);
260 
261  // Standard metadata field names
262  // (These fields should normally not be accessed directly, but rather
263  // via the accessor methods above, when available.)
264  // Note: Visual C++ requires these declarations to be separate statements.
265  static const char* const META_GRID_CLASS;
266  static const char* const META_GRID_CREATOR;
267  static const char* const META_GRID_NAME;
268  static const char* const META_SAVE_HALF_FLOAT;
269  static const char* const META_IS_LOCAL_SPACE;
270  static const char* const META_VECTOR_TYPE;
271  static const char* const META_FILE_BBOX_MIN;
272  static const char* const META_FILE_BBOX_MAX;
273  static const char* const META_FILE_COMPRESSION;
274  static const char* const META_FILE_MEM_BYTES;
275  static const char* const META_FILE_VOXEL_COUNT;
276 
277 
278  //
279  // Statistics
280  //
282  virtual Index64 activeVoxelCount() const = 0;
283 
286  virtual CoordBBox evalActiveVoxelBoundingBox() const = 0;
287 
289  virtual Coord evalActiveVoxelDim() const = 0;
290 
292  virtual Index64 memUsage() const = 0;
293 
298  void addStatsMetadata();
303  MetaMap::Ptr getStatsMetadata() const;
304 
305 
306  //
307  // Transform methods
308  //
310  math::Transform::Ptr transformPtr() { return mTransform; }
313  math::Transform::ConstPtr transformPtr() const { return mTransform; }
314  math::Transform::ConstPtr constTransformPtr() const { return mTransform; }
316 
317  math::Transform& transform() { return *mTransform; }
322  const math::Transform& transform() const { return *mTransform; }
323  const math::Transform& constTransform() const { return *mTransform; }
325  void setTransform(math::Transform::Ptr);
331 
333  Vec3d voxelSize() const { return transform().voxelSize(); }
336  Vec3d voxelSize(const Vec3d& xyz) const { return transform().voxelSize(xyz); }
338  bool hasUniformVoxels() const { return mTransform->hasUniformScale(); }
340  Vec3d indexToWorld(const Vec3d& xyz) const { return transform().indexToWorld(xyz); }
342  Vec3d indexToWorld(const Coord& ijk) const { return transform().indexToWorld(ijk); }
344  Vec3d worldToIndex(const Vec3d& xyz) const { return transform().worldToIndex(xyz); }
346 
347 
348  //
349  // I/O methods
350  //
353  virtual void readTopology(std::istream&) = 0;
356  virtual void writeTopology(std::ostream&) const = 0;
357 
359  virtual void readBuffers(std::istream&) = 0;
361  virtual void writeBuffers(std::ostream&) const = 0;
362 
364  void readTransform(std::istream& is) { transform().read(is); }
366  void writeTransform(std::ostream& os) const { transform().write(os); }
367 
369  virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const = 0;
370 
371 
372 protected:
374  GridBase(): mTransform(math::Transform::createLinearTransform()) {}
375 
377  GridBase(const GridBase& other): MetaMap(other), mTransform(other.mTransform->copy()) {}
378 
380  GridBase(const GridBase& other, ShallowCopy): MetaMap(other), mTransform(other.mTransform) {}
381 
383  static void registerGrid(const Name& type, GridFactory);
385  static void unregisterGrid(const Name& type);
386 
387 
388 private:
389  math::Transform::Ptr mTransform;
390 }; // class GridBase
391 
392 
394 
395 
396 typedef std::vector<GridBase::Ptr> GridPtrVec;
397 typedef GridPtrVec::iterator GridPtrVecIter;
398 typedef GridPtrVec::const_iterator GridPtrVecCIter;
399 typedef boost::shared_ptr<GridPtrVec> GridPtrVecPtr;
400 
401 typedef std::vector<GridBase::ConstPtr> GridCPtrVec;
402 typedef GridCPtrVec::iterator GridCPtrVecIter;
403 typedef GridCPtrVec::const_iterator GridCPtrVecCIter;
404 typedef boost::shared_ptr<GridCPtrVec> GridCPtrVecPtr;
405 
406 typedef std::set<GridBase::Ptr> GridPtrSet;
407 typedef GridPtrSet::iterator GridPtrSetIter;
408 typedef GridPtrSet::const_iterator GridPtrSetCIter;
409 typedef boost::shared_ptr<GridPtrSet> GridPtrSetPtr;
410 
411 typedef std::set<GridBase::ConstPtr> GridCPtrSet;
412 typedef GridCPtrSet::iterator GridCPtrSetIter;
413 typedef GridCPtrSet::const_iterator GridCPtrSetCIter;
414 typedef boost::shared_ptr<GridCPtrSet> GridCPtrSetPtr;
415 
416 
419 {
420  GridNamePred(const Name& name): name(name) {}
421  bool operator()(const GridBase::ConstPtr& g) const { return g && g->getName() == name; }
423 };
424 
426 template<typename GridPtrContainerT>
427 inline typename GridPtrContainerT::value_type
428 findGridByName(const GridPtrContainerT& container, const Name& name)
429 {
430  typedef typename GridPtrContainerT::value_type GridPtrT;
431  typename GridPtrContainerT::const_iterator it =
432  std::find_if(container.begin(), container.end(), GridNamePred(name));
433  return (it == container.end() ? GridPtrT() : *it);
434 }
435 
437 template<typename KeyT, typename GridPtrT>
438 inline GridPtrT
439 findGridByName(const std::map<KeyT, GridPtrT>& container, const Name& name)
440 {
441  typedef std::map<KeyT, GridPtrT> GridPtrMapT;
442  for (typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
443  it != end; ++it)
444  {
445  const GridPtrT& grid = it->second;
446  if (grid && grid->getName() == name) return grid;
447  }
448  return GridPtrT();
449 }
451 
452 
454 
455 
457 template<typename _TreeType>
458 class Grid: public GridBase
459 {
460 public:
461  typedef boost::shared_ptr<Grid> Ptr;
462  typedef boost::shared_ptr<const Grid> ConstPtr;
463 
464  typedef _TreeType TreeType;
465  typedef typename _TreeType::Ptr TreePtrType;
466  typedef typename _TreeType::ConstPtr ConstTreePtrType;
467  typedef typename _TreeType::ValueType ValueType;
468 
471 
472  typedef typename _TreeType::ValueOnIter ValueOnIter;
473  typedef typename _TreeType::ValueOnCIter ValueOnCIter;
474  typedef typename _TreeType::ValueOffIter ValueOffIter;
475  typedef typename _TreeType::ValueOffCIter ValueOffCIter;
476  typedef typename _TreeType::ValueAllIter ValueAllIter;
477  typedef typename _TreeType::ValueAllCIter ValueAllCIter;
478 
485  template<typename OtherValueType>
486  struct ValueConverter {
488  };
489 
491  static Ptr create(const ValueType& background);
493  static Ptr create();
496  static Ptr create(TreePtrType);
499  static Ptr create(const GridBase& other);
500 
501 
503  Grid();
505  explicit Grid(const ValueType& background);
509  explicit Grid(TreePtrType);
511  Grid(const Grid&);
513  Grid(const Grid&, ShallowCopy);
516  Grid(const GridBase&);
517 
518  virtual ~Grid() {}
519 
521  Ptr copy(CopyPolicy treePolicy = CP_SHARE) const;
527  virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const;
529 
530  Ptr deepCopy() const { return Ptr(new Grid(*this)); }
532  virtual GridBase::Ptr deepCopyGrid() const { return this->deepCopy(); }
534 
536  virtual Name type() const { return this->gridType(); }
538  static Name gridType() { return TreeType::treeType(); }
539 
540 
541  //
542  // Voxel access methods
543  //
545  virtual Name valueType() const { return tree().valueType(); }
546 
548  const ValueType& background() const { return mTree->background(); }
550  void setBackground(const ValueType& val) { tree().setBackground(val); }
551 
553  virtual bool empty() const { return tree().empty(); }
555  virtual void clear() { tree().clear(); }
556 
558  Accessor getAccessor() { return Accessor(tree()); }
560  ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
562  ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
564 
566  ValueOnIter beginValueOn() { return tree().beginValueOn(); }
568  ValueOnCIter beginValueOn() const { return tree().cbeginValueOn(); }
569  ValueOnCIter cbeginValueOn() const { return tree().cbeginValueOn(); }
571 
572  ValueOffIter beginValueOff() { return tree().beginValueOff(); }
574  ValueOffCIter beginValueOff() const { return tree().cbeginValueOff(); }
575  ValueOffCIter cbeginValueOff() const { return tree().cbeginValueOff(); }
577 
578  ValueAllIter beginValueAll() { return tree().beginValueAll(); }
580  ValueAllCIter beginValueAll() const { return tree().cbeginValueAll(); }
581  ValueAllCIter cbeginValueAll() const { return tree().cbeginValueAll(); }
583 
585  void evalMinMax(ValueType& minVal, ValueType& maxVal) const;
586 
595  void fill(const CoordBBox& bbox, const ValueType& value, bool active = true);
596 
602  void signedFloodFill() { tree().signedFloodFill(); }
603 
611  void signedFloodFill(const ValueType& outside, const ValueType& inside);
612 
617  void prune(const ValueType& tolerance = zeroVal<ValueType>()) { tree().prune(tolerance); }
619  virtual void pruneGrid(float tolerance = 0.0);
620 
626  void merge(Grid& other, MergePolicy policy = MERGE_ACTIVE_STATES);
627 
641  template<typename OtherTreeType>
642  void topologyUnion(const Grid<OtherTreeType>& other) { tree().topologyUnion(other.tree()); }
643 
657  template<typename OtherTreeType>
659  {
660  tree().topologyIntersection(other.tree());
661  }
662 
664 
665  //
666  // Statistics
667  //
669  virtual Index64 activeVoxelCount() const { return tree().activeVoxelCount(); }
671  virtual CoordBBox evalActiveVoxelBoundingBox() const;
673  virtual Coord evalActiveVoxelDim() const;
674 
677  virtual Index64 memUsage() const { return tree().memUsage(); }
678 
679 
680  //
681  // Tree methods
682  //
684  TreePtrType treePtr() { return mTree; }
687  ConstTreePtrType treePtr() const { return mTree; }
688  ConstTreePtrType constTreePtr() const { return mTree; }
689  virtual TreeBase::ConstPtr constBaseTreePtr() const { return mTree; }
691 
692  TreeType& tree() { return *mTree; }
697  const TreeType& tree() const { return *mTree; }
698  const TreeType& constTree() const { return *mTree; }
700 
706  virtual void setTree(TreeBase::Ptr);
707 
710  virtual void newTree();
711 
712 
713  //
714  // I/O methods
715  //
718  virtual void readTopology(std::istream&);
721  virtual void writeTopology(std::ostream&) const;
722 
724  virtual void readBuffers(std::istream&);
726  virtual void writeBuffers(std::ostream&) const;
727 
729  virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const;
730 
731 
732  //
733  // Registry methods
734  //
738  static void registerGrid() { GridBase::registerGrid(Grid::gridType(), Grid::factory); }
741 
742 
743 private:
745  Grid& operator=(const Grid& other);
746 
748  static GridBase::Ptr factory() { return Grid::create(); }
749 
750  TreePtrType mTree;
751 }; // class Grid
752 
753 
755 
756 
764 template<typename GridType>
765 inline typename GridType::Ptr
767 {
768  return GridBase::grid<GridType>(grid);
769 }
770 
771 
780 template<typename GridType>
781 inline typename GridType::ConstPtr
783 {
784  return GridBase::constGrid<GridType>(grid);
785 }
786 
787 
789 
790 
797 template<typename GridType>
798 inline typename GridType::Ptr
800 {
801  if (!grid || !grid->isType<GridType>()) return typename GridType::Ptr();
802  return gridPtrCast<GridType>(grid->deepCopyGrid());
803 }
804 
805 
806 template<typename GridType>
807 inline typename GridType::Ptr
809 {
810  if (!grid.isType<GridType>()) return typename GridType::Ptr();
811  return gridPtrCast<GridType>(grid.deepCopyGrid());
812 }
814 
815 
817 
818 
820 template<typename _TreeType>
824 {
825  typedef _TreeType TreeType;
826  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
827  typedef typename TreeType::Ptr TreePtrType;
828  typedef typename TreeType::ConstPtr ConstTreePtrType;
829  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
832  typedef typename GridType::Ptr GridPtrType;
835  typedef typename TreeType::ValueType ValueType;
839 
840  static TreeType& tree(TreeType& t) { return t; }
841  static TreeType& tree(GridType& g) { return g.tree(); }
842  static const TreeType& tree(const TreeType& t) { return t; }
843  static const TreeType& tree(const GridType& g) { return g.tree(); }
844  static const TreeType& constTree(TreeType& t) { return t; }
845  static const TreeType& constTree(GridType& g) { return g.constTree(); }
846  static const TreeType& constTree(const TreeType& t) { return t; }
847  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
848 };
849 
850 
852 template<typename _TreeType>
853 struct TreeAdapter<Grid<_TreeType> >
854 {
855  typedef _TreeType TreeType;
856  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
857  typedef typename TreeType::Ptr TreePtrType;
858  typedef typename TreeType::ConstPtr ConstTreePtrType;
859  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
862  typedef typename GridType::Ptr GridPtrType;
865  typedef typename TreeType::ValueType ValueType;
869 
870  static TreeType& tree(TreeType& t) { return t; }
871  static TreeType& tree(GridType& g) { return g.tree(); }
872  static const TreeType& tree(const TreeType& t) { return t; }
873  static const TreeType& tree(const GridType& g) { return g.tree(); }
874  static const TreeType& constTree(TreeType& t) { return t; }
875  static const TreeType& constTree(GridType& g) { return g.constTree(); }
876  static const TreeType& constTree(const TreeType& t) { return t; }
877  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
878 };
879 
881 template<typename _TreeType>
882 struct TreeAdapter<tree::ValueAccessor<_TreeType> >
883 {
884  typedef _TreeType TreeType;
885  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
886  typedef typename TreeType::Ptr TreePtrType;
887  typedef typename TreeType::ConstPtr ConstTreePtrType;
888  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
891  typedef typename GridType::Ptr GridPtrType;
894  typedef typename TreeType::ValueType ValueType;
898 
899  static TreeType& tree(TreeType& t) { return t; }
900  static TreeType& tree(GridType& g) { return g.tree(); }
901  static TreeType& tree(AccessorType& a) { return a.tree(); }
902  static const TreeType& tree(const TreeType& t) { return t; }
903  static const TreeType& tree(const GridType& g) { return g.tree(); }
904  static const TreeType& tree(const AccessorType& a) { return a.tree(); }
905  static const TreeType& constTree(TreeType& t) { return t; }
906  static const TreeType& constTree(GridType& g) { return g.constTree(); }
907  static const TreeType& constTree(const TreeType& t) { return t; }
908  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
909 };
910 
912 
913 
915 
916 
917 template<typename GridType>
918 inline typename GridType::Ptr
920 {
921  // The string comparison on type names is slower than a dynamic_pointer_cast, but
922  // it is safer when pointers cross dso boundaries, as they do in many Houdini nodes.
923  if (grid && grid->type() == GridType::gridType()) {
924  return boost::static_pointer_cast<GridType>(grid);
925  }
926  return typename GridType::Ptr();
927 }
928 
929 
930 template<typename GridType>
931 inline typename GridType::ConstPtr
933 {
934  return boost::const_pointer_cast<const GridType>(
935  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
936 }
937 
938 
939 template<typename GridType>
940 inline typename GridType::ConstPtr
942 {
943  return boost::const_pointer_cast<const GridType>(GridBase::grid<GridType>(grid));
944 }
945 
946 
947 template<typename GridType>
948 inline typename GridType::ConstPtr
950 {
951  return boost::const_pointer_cast<const GridType>(
952  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
953 }
954 
955 
956 inline TreeBase::Ptr
958 {
959  return boost::const_pointer_cast<TreeBase>(this->constBaseTreePtr());
960 }
961 
962 
963 inline void
965 {
966  if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
967  mTransform = xform;
968 }
969 
970 
972 
973 
974 template<typename TreeT>
975 inline Grid<TreeT>::Grid(): mTree(new TreeType)
976 {
977 }
978 
979 
980 template<typename TreeT>
981 inline Grid<TreeT>::Grid(const ValueType &background): mTree(new TreeType(background))
982 {
983 }
984 
985 
986 template<typename TreeT>
987 inline Grid<TreeT>::Grid(TreePtrType tree): mTree(tree)
988 {
989  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
990 }
991 
992 
993 template<typename TreeT>
994 inline Grid<TreeT>::Grid(const Grid& other):
995  GridBase(other),
996  mTree(boost::static_pointer_cast<TreeType>(other.mTree->copy()))
997 {
998 }
999 
1000 
1001 template<typename TreeT>
1002 inline Grid<TreeT>::Grid(const Grid& other, ShallowCopy):
1003  GridBase(other, ShallowCopy()),
1004  mTree(other.mTree)
1005 {
1006 }
1007 
1008 
1009 template<typename TreeT>
1010 inline Grid<TreeT>::Grid(const GridBase& other):
1011  GridBase(other),
1012  mTree(new TreeType)
1013 {
1014 }
1015 
1016 
1017 //static
1018 template<typename TreeT>
1019 inline typename Grid<TreeT>::Ptr
1021 {
1022  return Grid::create(zeroVal<ValueType>());
1023 }
1024 
1025 
1026 //static
1027 template<typename TreeT>
1028 inline typename Grid<TreeT>::Ptr
1029 Grid<TreeT>::create(const ValueType& background)
1030 {
1031  return Ptr(new Grid(background));
1032 }
1033 
1034 
1035 //static
1036 template<typename TreeT>
1037 inline typename Grid<TreeT>::Ptr
1039 {
1040  return Ptr(new Grid(tree));
1041 }
1042 
1043 
1044 //static
1045 template<typename TreeT>
1046 inline typename Grid<TreeT>::Ptr
1048 {
1049  return Ptr(new Grid(other));
1050 }
1051 
1052 
1054 
1055 
1056 template<typename TreeT>
1057 inline typename Grid<TreeT>::Ptr
1059 {
1060  Ptr ret;
1061  switch (treePolicy) {
1062  case CP_NEW:
1063  ret.reset(new Grid(*this, ShallowCopy()));
1064  ret->newTree();
1065  break;
1066  case CP_COPY:
1067  ret.reset(new Grid(*this));
1068  break;
1069  case CP_SHARE:
1070  ret.reset(new Grid(*this, ShallowCopy()));
1071  break;
1072  }
1073  return ret;
1074 }
1075 
1076 
1077 template<typename TreeT>
1078 inline GridBase::Ptr
1080 {
1081  return this->copy(treePolicy);
1082 }
1083 
1084 
1086 
1087 
1088 template<typename TreeT>
1089 inline void
1091 {
1092  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1093  if (tree->type() != TreeType::treeType()) {
1094  OPENVDB_THROW(TypeError, "Cannot assign a tree of type "
1095  + tree->type() + " to a grid of type " + this->type());
1096  }
1097  mTree = boost::static_pointer_cast<TreeType>(tree);
1098 }
1099 
1100 
1101 template<typename TreeT>
1102 inline void
1104 {
1105  mTree.reset(new TreeType(this->background()));
1106 }
1107 
1108 
1109 template<typename TreeT>
1110 inline void
1111 Grid<TreeT>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1112 {
1113  tree().fill(bbox, value, active);
1114 }
1115 
1116 
1117 template<typename TreeT>
1118 inline void
1119 Grid<TreeT>::signedFloodFill(const ValueType& outside, const ValueType& inside)
1120 {
1121  tree().signedFloodFill(outside, inside);
1122 }
1123 
1124 
1125 template<typename TreeT>
1126 inline void
1127 Grid<TreeT>::pruneGrid(float tolerance)
1128 {
1129  this->prune(ValueType(zeroVal<ValueType>() + tolerance));
1130 }
1131 
1132 
1133 template<typename TreeT>
1134 inline void
1136 {
1137  tree().merge(other.tree(), policy);
1138 }
1139 
1140 
1141 template<typename TreeT>
1142 inline void
1144 {
1145  tree().evalMinMax(minVal, maxVal);
1146 }
1147 
1148 
1149 template<typename TreeT>
1150 inline CoordBBox
1152 {
1153  CoordBBox bbox;
1154  tree().evalActiveVoxelBoundingBox(bbox);
1155  return bbox;
1156 }
1157 
1158 
1159 template<typename TreeT>
1160 inline Coord
1162 {
1163  Coord dim;
1164  const bool nonempty = tree().evalActiveVoxelDim(dim);
1165  return (nonempty ? dim : Coord());
1166 }
1167 
1168 
1170 
1171 
1174 
1175 template<typename TreeT>
1176 inline void
1177 Grid<TreeT>::readTopology(std::istream& is)
1178 {
1179  tree().readTopology(is, saveFloatAsHalf());
1180 }
1181 
1182 
1183 template<typename TreeT>
1184 inline void
1185 Grid<TreeT>::writeTopology(std::ostream& os) const
1186 {
1187  tree().writeTopology(os, saveFloatAsHalf());
1188 }
1189 
1190 
1191 template<typename TreeT>
1192 inline void
1193 Grid<TreeT>::readBuffers(std::istream& is)
1194 {
1195  tree().readBuffers(is, saveFloatAsHalf());
1196 }
1197 
1198 
1199 template<typename TreeT>
1200 inline void
1201 Grid<TreeT>::writeBuffers(std::ostream& os) const
1202 {
1203  tree().writeBuffers(os, saveFloatAsHalf());
1204 }
1205 
1206 
1207 template<typename TreeT>
1208 inline void
1209 Grid<TreeT>::print(std::ostream& os, int verboseLevel) const
1210 {
1211  tree().print(os, verboseLevel);
1212 
1213  if (metaCount() > 0) {
1214  os << "Additional metadata:" << std::endl;
1215  for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1216  os << " " << it->first;
1217  if (it->second) {
1218  const std::string value = it->second->str();
1219  if (!value.empty()) os << ": " << value;
1220  }
1221  os << "\n";
1222  }
1223  }
1224 
1225  os << "Transform:" << std::endl;
1226  transform().print(os, /*indent=*/" ");
1227  os << std::endl;
1228 }
1229 
1230 
1232 
1233 
1234 template<typename GridType>
1235 inline typename GridType::Ptr
1236 createGrid(const typename GridType::ValueType& background)
1237 {
1238  return GridType::create(background);
1239 }
1240 
1241 
1242 template<typename GridType>
1243 inline typename GridType::Ptr
1245 {
1246  return GridType::create();
1247 }
1248 
1249 
1250 template<typename TreePtrType>
1252 createGrid(TreePtrType tree)
1253 {
1254  typedef typename TreePtrType::element_type TreeType;
1255  return Grid<TreeType>::create(tree);
1256 }
1257 
1258 
1259 template<typename GridType>
1260 typename GridType::Ptr
1261 createLevelSet(Real voxelSize, Real halfWidth)
1262 {
1263  typedef typename GridType::ValueType ValueType;
1264 
1265  // GridType::ValueType is required to be a floating-point scalar.
1266  BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
1267 
1268  typename GridType::Ptr grid = GridType::create(
1269  /*background=*/static_cast<ValueType>(voxelSize * halfWidth));
1270  grid->setTransform(math::Transform::createLinearTransform(voxelSize));
1271  grid->setGridClass(GRID_LEVEL_SET);
1272  return grid;
1273 }
1274 
1275 } // namespace OPENVDB_VERSION_NAME
1276 } // namespace openvdb
1277 
1278 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
1279 
1280 // Copyright (c) 2012-2013 DreamWorks Animation LLC
1281 // All rights reserved. This software is distributed under the
1282 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Definition: Types.h:343
void setBackground(const ValueType &val)
Replace this grid&#39;s background value.
Definition: Grid.h:550
CopyPolicy
Definition: Types.h:338
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:885
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1143
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:418
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:162
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:782
static Transform::Ptr createLinearTransform(double voxelSize=1.0)
Create and return a shared pointer to a new transform.
boost::shared_ptr< MetaMap > Ptr
Definition: MetaMap.h:51
static TreeType & tree(GridType &g)
Definition: Grid.h:841
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:833
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:874
boost::shared_ptr< const TreeBase > ConstPtr
Definition: Tree.h:68
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:401
_TreeType TreeType
Definition: Grid.h:464
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:408
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:823
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:581
OPENVDB_IMPORT void setGridClass(std::ios_base &, uint32_t)
Associate with the given stream the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently ...
virtual void pruneGrid(float tolerance=0.0)
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1127
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1135
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
virtual Name type() const
Return the name of this grid&#39;s type.
Definition: Grid.h:536
GridNamePred(const Name &name)
Definition: Grid.h:420
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:421
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:975
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:396
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:838
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:856
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid&#39;s values (tile and voxel).
Definition: Grid.h:580
virtual void clear()
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:555
_TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:477
tree::ValueAccessor< _TreeType > Accessor
Definition: Grid.h:469
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:766
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
static const char *const META_VECTOR_TYPE
Definition: Grid.h:270
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:887
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:846
const math::Transform & transform() const
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:322
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:738
GridType::Ptr GridPtrType
Definition: Grid.h:832
const ValueType & background() const
Return this grid&#39;s background value.
Definition: Grid.h:548
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:314
TreeType::Ptr TreePtrType
Definition: Grid.h:827
tree::TreeBase TreeBase
Definition: Grid.h:52
virtual Index64 activeVoxelCount() const
Return the number of active voxels.
Definition: Grid.h:669
TreeType & tree()
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:696
double Real
Definition: Types.h:62
static TreeType & tree(AccessorType &a)
Definition: Grid.h:901
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:893
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:896
Definition: Types.h:338
static const char *const META_GRID_CLASS
Definition: Grid.h:265
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:919
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:826
static TreeType & tree(TreeType &t)
Definition: Grid.h:840
static TreeType & tree(TreeType &t)
Definition: Grid.h:870
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:740
GridType::Ptr createLevelSet(Real voxelSize=1.0, Real halfWidth=LEVEL_SET_HALF_WIDTH)
Create a new grid of type GridType classified as a &quot;Level Set&quot;, i.e., a narrow-band level set...
Definition: Grid.h:1261
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:964
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:1185
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:269
GridType::Ptr GridPtrType
Definition: Grid.h:862
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:858
const TreeType & tree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:697
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1020
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:406
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:834
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:1079
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:905
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:407
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:574
_TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:476
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:866
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:897
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:890
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:687
boost::shared_ptr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:404
virtual ~Grid()
Definition: Grid.h:518
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:688
Name name
Definition: Grid.h:422
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:1111
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:888
TreeType::ValueType ValueType
Definition: Grid.h:894
virtual void writeBuffers(std::ostream &) const
Write out all data buffers for this grid.
Definition: Grid.h:1201
std::string Name
Definition: Name.h:44
Abstract base class for typed grids.
Definition: Grid.h:103
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:532
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:863
_TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:472
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:895
boost::shared_ptr< Grid > Ptr
Definition: Grid.h:461
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:411
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:868
GridBase(const GridBase &other, ShallowCopy)
Copy another grid&#39;s metadata but share its transform.
Definition: Grid.h:380
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:867
MetadataMap::const_iterator ConstMetaIterator
Definition: MetaMap.h:56
#define OPENVDB_VERSION_NAME
Definition: version.h:45
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:275
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:273
Vec3d voxelSize() const
Return the size of this grid&#39;s voxels.
Definition: Grid.h:333
void signedFloodFill()
Set the values of all inactive voxels and tiles of a narrow-band level set from the signs of the acti...
Definition: Grid.h:602
static const TreeType & tree(const GridType &g)
Definition: Grid.h:873
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:689
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:736
virtual Name valueType() const
Return the name of the type of a voxel&#39;s value (e.g., &quot;float&quot; or &quot;vec3d&quot;).
Definition: Grid.h:545
virtual void setTree(TreeBase::Ptr)
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1090
Grid< typename TreeType::template ValueConverter< OtherValueType >::Type > Type
Definition: Grid.h:487
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:538
void topologyIntersection(const Grid< OtherTreeType > &other)
Intersects this tree&#39;s set of active values with the active values of the other tree, whose ValueType may be different.
Definition: Grid.h:658
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:847
static const TreeType & constTree(GridType &g)
Definition: Grid.h:845
TreeType::ValueType ValueType
Definition: Grid.h:865
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:842
TreeType::ValueType ValueType
Definition: Grid.h:835
TreeType::Ptr TreePtrType
Definition: Grid.h:857
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:892
virtual void newTree()
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1103
virtual void readBuffers(std::istream &)
Read all data buffers for this grid.
Definition: Grid.h:1193
virtual Coord evalActiveVoxelDim() const
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1161
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:374
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:272
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:569
_TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:475
VecType
Definition: Types.h:165
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:872
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:907
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid&#39;s inactive values (tile and voxel).
Definition: Grid.h:575
_TreeType TreeType
Definition: Grid.h:825
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:271
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:403
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid&#39;s voxels.
Definition: Grid.h:558
Vec3< double > Vec3d
Definition: Vec3.h:605
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:1177
virtual bool empty() const
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:553
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid&#39;s.
boost::shared_ptr< const Grid > ConstPtr
Definition: Grid.h:462
Definition: ValueAccessor.h:173
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:413
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:837
static TreeType & tree(GridType &g)
Definition: Grid.h:900
virtual CoordBBox evalActiveVoxelBoundingBox() const
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1151
Provides functionality storing type agnostic metadata information. Grids and other structures can inh...
Definition: MetaMap.h:48
static TreeType & tree(TreeType &t)
Definition: Grid.h:899
Calculate an axis-aligned bounding box in index space from a bounding sphere in world space...
Definition: Transform.h:65
_TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:466
Definition: Types.h:338
Grid< TreeType > GridType
Definition: Grid.h:860
tree::ValueAccessor< const _TreeType > ConstAccessor
Definition: Grid.h:470
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:268
boost::shared_ptr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:414
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:274
boost::shared_ptr< TreeBase > Ptr
Definition: Tree.h:67
void prune(const ValueType &tolerance=zeroVal< ValueType >())
Reduce the memory footprint of this grid by increasing its sparseness either losslessly (tolerance = ...
Definition: Grid.h:617
_TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:473
boost::shared_ptr< Transform > Ptr
Definition: Transform.h:68
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:902
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:143
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:397
TreeType & tree() const
Return a reference to the tree associated with this accessor.
Definition: ValueAccessor.h:117
static const TreeType & tree(const GridType &g)
Definition: Grid.h:903
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
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:957
OPENVDB_IMPORT uint32_t getGridClass(std::ios_base &)
Return the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently being read from or writte...
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:908
MergePolicy
Definition: Types.h:188
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:402
Definition: Exceptions.h:88
static const TreeType & tree(const GridType &g)
Definition: Grid.h:843
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:861
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:844
static TreeType & tree(GridType &g)
Definition: Grid.h:871
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:1058
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
boost::shared_ptr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:399
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:398
GridBase(const GridBase &other)
Deep copy another grid&#39;s metadata and transform.
Definition: Grid.h:377
const TreeType & constTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:698
GridClass
Definition: Types.h:135
static const char *const META_GRID_CREATOR
Definition: Grid.h:266
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:904
GridType::Ptr deepCopyTypedGrid(const GridBase::ConstPtr &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:799
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:366
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:412
_TreeType::Ptr TreePtrType
Definition: Grid.h:465
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid&#39;s active values (tile and voxel).
Definition: Grid.h:568
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid&#39;s voxel at position (x, y, z).
Definition: Grid.h:336
boost::shared_ptr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:409
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const
Output a human-readable description of this grid.
Definition: Grid.h:1209
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:828
_TreeType TreeType
Definition: Grid.h:855
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:313
static const TreeType & constTree(GridType &g)
Definition: Grid.h:906
Definition: Exceptions.h:87
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:829
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:145
boost::shared_ptr< const Transform > ConstPtr
Definition: Transform.h:69
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:859
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
Grid< TreeType > GridType
Definition: Grid.h:830
_TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:474
static const TreeType & constTree(GridType &g)
Definition: Grid.h:875
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:877
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:876
uint64_t Index64
Definition: Types.h:55
const math::Transform & constTransform() const
Return a reference to this grid&#39;s transform, which might be shared with other grids.
Definition: Grid.h:323
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid&#39;s transform to the given coordinates.
Definition: Grid.h:342
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:864
const TreeBase & constBaseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:175
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:642
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:941
Definition: Types.h:338
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1236
_TreeType::ValueType ValueType
Definition: Grid.h:467
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:338
virtual ~GridBase()
Definition: Grid.h:112
Definition: Types.h:137
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
ValueConverter&lt;T&gt;::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:486
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:831
GridPtrContainerT::value_type findGridByName(const GridPtrContainerT &container, const Name &name)
Return the first grid in the given container whose name is name.
Definition: Grid.h:428
const TreeBase & baseTree() const
Return a reference to this grid&#39;s tree, which might be shared with other grids.
Definition: Grid.h:174
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid&#39;s voxels.
Definition: Grid.h:562
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:836
static const char *const META_GRID_NAME
Definition: Grid.h:267
virtual Index64 memUsage() const
Definition: Grid.h:677
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:364
Base class for typed trees.
Definition: Tree.h:64