OpenVDB  2.3.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&);
517  template<typename OtherTreeType>
518  explicit Grid(const Grid<OtherTreeType>&);
520  Grid(const Grid&, ShallowCopy);
523  Grid(const GridBase&);
524 
525  virtual ~Grid() {}
526 
528  Ptr copy(CopyPolicy treePolicy = CP_SHARE) const;
534  virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy = CP_SHARE) const;
536 
537  Ptr deepCopy() const { return Ptr(new Grid(*this)); }
539  virtual GridBase::Ptr deepCopyGrid() const { return this->deepCopy(); }
541 
543  virtual Name type() const { return this->gridType(); }
545  static Name gridType() { return TreeType::treeType(); }
546 
547 
548  //
549  // Voxel access methods
550  //
552  virtual Name valueType() const { return tree().valueType(); }
553 
555  const ValueType& background() const { return mTree->background(); }
557  void setBackground(const ValueType& val) { tree().setBackground(val); }
558 
560  virtual bool empty() const { return tree().empty(); }
562  virtual void clear() { tree().clear(); }
563 
565  Accessor getAccessor() { return Accessor(tree()); }
567  ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
569  ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
571 
573  ValueOnIter beginValueOn() { return tree().beginValueOn(); }
575  ValueOnCIter beginValueOn() const { return tree().cbeginValueOn(); }
576  ValueOnCIter cbeginValueOn() const { return tree().cbeginValueOn(); }
578 
579  ValueOffIter beginValueOff() { return tree().beginValueOff(); }
581  ValueOffCIter beginValueOff() const { return tree().cbeginValueOff(); }
582  ValueOffCIter cbeginValueOff() const { return tree().cbeginValueOff(); }
584 
585  ValueAllIter beginValueAll() { return tree().beginValueAll(); }
587  ValueAllCIter beginValueAll() const { return tree().cbeginValueAll(); }
588  ValueAllCIter cbeginValueAll() const { return tree().cbeginValueAll(); }
590 
592  void evalMinMax(ValueType& minVal, ValueType& maxVal) const;
593 
602  void fill(const CoordBBox& bbox, const ValueType& value, bool active = true);
603 
609  void signedFloodFill() { tree().signedFloodFill(); }
610 
618  void signedFloodFill(const ValueType& outside, const ValueType& inside);
619 
624  void prune(const ValueType& tolerance = zeroVal<ValueType>()) { tree().prune(tolerance); }
626  virtual void pruneGrid(float tolerance = 0.0);
627 
633  void merge(Grid& other, MergePolicy policy = MERGE_ACTIVE_STATES);
634 
648  template<typename OtherTreeType>
649  void topologyUnion(const Grid<OtherTreeType>& other);
650 
663  template<typename OtherTreeType>
664  void topologyIntersection(const Grid<OtherTreeType>& other);
665 
676  template<typename OtherTreeType>
677  void topologyDifference(const Grid<OtherTreeType>& other);
678 
679  //
680  // Statistics
681  //
683  virtual Index64 activeVoxelCount() const { return tree().activeVoxelCount(); }
685  virtual CoordBBox evalActiveVoxelBoundingBox() const;
687  virtual Coord evalActiveVoxelDim() const;
688 
691  virtual Index64 memUsage() const { return tree().memUsage(); }
692 
693 
694  //
695  // Tree methods
696  //
698  TreePtrType treePtr() { return mTree; }
701  ConstTreePtrType treePtr() const { return mTree; }
702  ConstTreePtrType constTreePtr() const { return mTree; }
703  virtual TreeBase::ConstPtr constBaseTreePtr() const { return mTree; }
705 
706  TreeType& tree() { return *mTree; }
711  const TreeType& tree() const { return *mTree; }
712  const TreeType& constTree() const { return *mTree; }
714 
720  virtual void setTree(TreeBase::Ptr);
721 
724  virtual void newTree();
725 
726 
727  //
728  // I/O methods
729  //
732  virtual void readTopology(std::istream&);
735  virtual void writeTopology(std::ostream&) const;
736 
738  virtual void readBuffers(std::istream&);
740  virtual void writeBuffers(std::ostream&) const;
741 
743  virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const;
744 
745 
746  //
747  // Registry methods
748  //
752  static void registerGrid() { GridBase::registerGrid(Grid::gridType(), Grid::factory); }
755 
756 
757 private:
759  Grid& operator=(const Grid& other);
760 
762  static GridBase::Ptr factory() { return Grid::create(); }
763 
764  TreePtrType mTree;
765 }; // class Grid
766 
767 
769 
770 
778 template<typename GridType>
779 inline typename GridType::Ptr
781 {
782  return GridBase::grid<GridType>(grid);
783 }
784 
785 
794 template<typename GridType>
795 inline typename GridType::ConstPtr
797 {
798  return GridBase::constGrid<GridType>(grid);
799 }
800 
801 
803 
804 
811 template<typename GridType>
812 inline typename GridType::Ptr
814 {
815  if (!grid || !grid->isType<GridType>()) return typename GridType::Ptr();
816  return gridPtrCast<GridType>(grid->deepCopyGrid());
817 }
818 
819 
820 template<typename GridType>
821 inline typename GridType::Ptr
823 {
824  if (!grid.isType<GridType>()) return typename GridType::Ptr();
825  return gridPtrCast<GridType>(grid.deepCopyGrid());
826 }
828 
829 
831 
832 
834 template<typename _TreeType>
838 {
839  typedef _TreeType TreeType;
840  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
841  typedef typename TreeType::Ptr TreePtrType;
842  typedef typename TreeType::ConstPtr ConstTreePtrType;
843  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
846  typedef typename GridType::Ptr GridPtrType;
849  typedef typename TreeType::ValueType ValueType;
853 
854  static TreeType& tree(TreeType& t) { return t; }
855  static TreeType& tree(GridType& g) { return g.tree(); }
856  static const TreeType& tree(const TreeType& t) { return t; }
857  static const TreeType& tree(const GridType& g) { return g.tree(); }
858  static const TreeType& constTree(TreeType& t) { return t; }
859  static const TreeType& constTree(GridType& g) { return g.constTree(); }
860  static const TreeType& constTree(const TreeType& t) { return t; }
861  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
862 };
863 
864 
866 template<typename _TreeType>
867 struct TreeAdapter<Grid<_TreeType> >
868 {
869  typedef _TreeType TreeType;
870  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
871  typedef typename TreeType::Ptr TreePtrType;
872  typedef typename TreeType::ConstPtr ConstTreePtrType;
873  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
876  typedef typename GridType::Ptr GridPtrType;
879  typedef typename TreeType::ValueType ValueType;
883 
884  static TreeType& tree(TreeType& t) { return t; }
885  static TreeType& tree(GridType& g) { return g.tree(); }
886  static const TreeType& tree(const TreeType& t) { return t; }
887  static const TreeType& tree(const GridType& g) { return g.tree(); }
888  static const TreeType& constTree(TreeType& t) { return t; }
889  static const TreeType& constTree(GridType& g) { return g.constTree(); }
890  static const TreeType& constTree(const TreeType& t) { return t; }
891  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
892 };
893 
895 template<typename _TreeType>
896 struct TreeAdapter<tree::ValueAccessor<_TreeType> >
897 {
898  typedef _TreeType TreeType;
899  typedef typename boost::remove_const<TreeType>::type NonConstTreeType;
900  typedef typename TreeType::Ptr TreePtrType;
901  typedef typename TreeType::ConstPtr ConstTreePtrType;
902  typedef typename NonConstTreeType::Ptr NonConstTreePtrType;
905  typedef typename GridType::Ptr GridPtrType;
908  typedef typename TreeType::ValueType ValueType;
912 
913  static TreeType& tree(TreeType& t) { return t; }
914  static TreeType& tree(GridType& g) { return g.tree(); }
915  static TreeType& tree(AccessorType& a) { return a.tree(); }
916  static const TreeType& tree(const TreeType& t) { return t; }
917  static const TreeType& tree(const GridType& g) { return g.tree(); }
918  static const TreeType& tree(const AccessorType& a) { return a.tree(); }
919  static const TreeType& constTree(TreeType& t) { return t; }
920  static const TreeType& constTree(GridType& g) { return g.constTree(); }
921  static const TreeType& constTree(const TreeType& t) { return t; }
922  static const TreeType& constTree(const GridType& g) { return g.constTree(); }
923 };
924 
926 
927 
929 
930 
931 template<typename GridType>
932 inline typename GridType::Ptr
934 {
935  // The string comparison on type names is slower than a dynamic_pointer_cast, but
936  // it is safer when pointers cross dso boundaries, as they do in many Houdini nodes.
937  if (grid && grid->type() == GridType::gridType()) {
938  return boost::static_pointer_cast<GridType>(grid);
939  }
940  return typename GridType::Ptr();
941 }
942 
943 
944 template<typename GridType>
945 inline typename GridType::ConstPtr
947 {
948  return boost::const_pointer_cast<const GridType>(
949  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
950 }
951 
952 
953 template<typename GridType>
954 inline typename GridType::ConstPtr
956 {
957  return boost::const_pointer_cast<const GridType>(GridBase::grid<GridType>(grid));
958 }
959 
960 
961 template<typename GridType>
962 inline typename GridType::ConstPtr
964 {
965  return boost::const_pointer_cast<const GridType>(
966  GridBase::grid<GridType>(boost::const_pointer_cast<GridBase>(grid)));
967 }
968 
969 
970 inline TreeBase::Ptr
972 {
973  return boost::const_pointer_cast<TreeBase>(this->constBaseTreePtr());
974 }
975 
976 
977 inline void
979 {
980  if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
981  mTransform = xform;
982 }
983 
984 
986 
987 
988 template<typename TreeT>
989 inline Grid<TreeT>::Grid(): mTree(new TreeType)
990 {
991 }
992 
993 
994 template<typename TreeT>
995 inline Grid<TreeT>::Grid(const ValueType &background): mTree(new TreeType(background))
996 {
997 }
998 
999 
1000 template<typename TreeT>
1001 inline Grid<TreeT>::Grid(TreePtrType tree): mTree(tree)
1002 {
1003  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1004 }
1005 
1006 
1007 template<typename TreeT>
1008 inline Grid<TreeT>::Grid(const Grid& other):
1009  GridBase(other),
1010  mTree(boost::static_pointer_cast<TreeType>(other.mTree->copy()))
1011 {
1012 }
1013 
1014 
1015 template<typename TreeT>
1016 template<typename OtherTreeType>
1018  GridBase(other),
1019  mTree(new TreeType(other.constTree()))
1020 {
1021 }
1022 
1023 
1024 template<typename TreeT>
1025 inline Grid<TreeT>::Grid(const Grid& other, ShallowCopy):
1026  GridBase(other, ShallowCopy()),
1027  mTree(other.mTree)
1028 {
1029 }
1030 
1031 
1032 template<typename TreeT>
1033 inline Grid<TreeT>::Grid(const GridBase& other):
1034  GridBase(other),
1035  mTree(new TreeType)
1036 {
1037 }
1038 
1039 
1040 //static
1041 template<typename TreeT>
1042 inline typename Grid<TreeT>::Ptr
1044 {
1045  return Grid::create(zeroVal<ValueType>());
1046 }
1047 
1048 
1049 //static
1050 template<typename TreeT>
1051 inline typename Grid<TreeT>::Ptr
1052 Grid<TreeT>::create(const ValueType& background)
1053 {
1054  return Ptr(new Grid(background));
1055 }
1056 
1057 
1058 //static
1059 template<typename TreeT>
1060 inline typename Grid<TreeT>::Ptr
1062 {
1063  return Ptr(new Grid(tree));
1064 }
1065 
1066 
1067 //static
1068 template<typename TreeT>
1069 inline typename Grid<TreeT>::Ptr
1071 {
1072  return Ptr(new Grid(other));
1073 }
1074 
1075 
1077 
1078 
1079 template<typename TreeT>
1080 inline typename Grid<TreeT>::Ptr
1082 {
1083  Ptr ret;
1084  switch (treePolicy) {
1085  case CP_NEW:
1086  ret.reset(new Grid(*this, ShallowCopy()));
1087  ret->newTree();
1088  break;
1089  case CP_COPY:
1090  ret.reset(new Grid(*this));
1091  break;
1092  case CP_SHARE:
1093  ret.reset(new Grid(*this, ShallowCopy()));
1094  break;
1095  }
1096  return ret;
1097 }
1098 
1099 
1100 template<typename TreeT>
1101 inline GridBase::Ptr
1103 {
1104  return this->copy(treePolicy);
1105 }
1106 
1107 
1109 
1110 
1111 template<typename TreeT>
1112 inline void
1114 {
1115  if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1116  if (tree->type() != TreeType::treeType()) {
1117  OPENVDB_THROW(TypeError, "Cannot assign a tree of type "
1118  + tree->type() + " to a grid of type " + this->type());
1119  }
1120  mTree = boost::static_pointer_cast<TreeType>(tree);
1121 }
1122 
1123 
1124 template<typename TreeT>
1125 inline void
1127 {
1128  mTree.reset(new TreeType(this->background()));
1129 }
1130 
1131 
1133 
1134 
1135 template<typename TreeT>
1136 inline void
1137 Grid<TreeT>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1138 {
1139  tree().fill(bbox, value, active);
1140 }
1141 
1142 
1143 template<typename TreeT>
1144 inline void
1145 Grid<TreeT>::signedFloodFill(const ValueType& outside, const ValueType& inside)
1146 {
1147  tree().signedFloodFill(outside, inside);
1148 }
1149 
1150 
1151 template<typename TreeT>
1152 inline void
1153 Grid<TreeT>::pruneGrid(float tolerance)
1154 {
1155  this->prune(ValueType(zeroVal<ValueType>() + tolerance));
1156 }
1157 
1158 
1159 template<typename TreeT>
1160 inline void
1162 {
1163  tree().merge(other.tree(), policy);
1164 }
1165 
1166 
1167 template<typename TreeT>
1168 template<typename OtherTreeType>
1169 inline void
1171 {
1172  tree().topologyUnion(other.tree());
1173 }
1174 
1175 
1176 template<typename TreeT>
1177 template<typename OtherTreeType>
1178 inline void
1180 {
1181  tree().topologyIntersection(other.tree());
1182 }
1183 
1184 
1185 template<typename TreeT>
1186 template<typename OtherTreeType>
1187 inline void
1189 {
1190  tree().topologyDifference(other.tree());
1191 }
1192 
1193 
1195 
1196 
1197 template<typename TreeT>
1198 inline void
1200 {
1201  tree().evalMinMax(minVal, maxVal);
1202 }
1203 
1204 
1205 template<typename TreeT>
1206 inline CoordBBox
1208 {
1209  CoordBBox bbox;
1210  tree().evalActiveVoxelBoundingBox(bbox);
1211  return bbox;
1212 }
1213 
1214 
1215 template<typename TreeT>
1216 inline Coord
1218 {
1219  Coord dim;
1220  const bool nonempty = tree().evalActiveVoxelDim(dim);
1221  return (nonempty ? dim : Coord());
1222 }
1223 
1224 
1226 
1227 
1230 
1231 template<typename TreeT>
1232 inline void
1233 Grid<TreeT>::readTopology(std::istream& is)
1234 {
1235  tree().readTopology(is, saveFloatAsHalf());
1236 }
1237 
1238 
1239 template<typename TreeT>
1240 inline void
1241 Grid<TreeT>::writeTopology(std::ostream& os) const
1242 {
1243  tree().writeTopology(os, saveFloatAsHalf());
1244 }
1245 
1246 
1247 template<typename TreeT>
1248 inline void
1249 Grid<TreeT>::readBuffers(std::istream& is)
1250 {
1251  tree().readBuffers(is, saveFloatAsHalf());
1252 }
1253 
1254 
1255 template<typename TreeT>
1256 inline void
1257 Grid<TreeT>::writeBuffers(std::ostream& os) const
1258 {
1259  tree().writeBuffers(os, saveFloatAsHalf());
1260 }
1261 
1262 
1263 template<typename TreeT>
1264 inline void
1265 Grid<TreeT>::print(std::ostream& os, int verboseLevel) const
1266 {
1267  tree().print(os, verboseLevel);
1268 
1269  if (metaCount() > 0) {
1270  os << "Additional metadata:" << std::endl;
1271  for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1272  os << " " << it->first;
1273  if (it->second) {
1274  const std::string value = it->second->str();
1275  if (!value.empty()) os << ": " << value;
1276  }
1277  os << "\n";
1278  }
1279  }
1280 
1281  os << "Transform:" << std::endl;
1282  transform().print(os, /*indent=*/" ");
1283  os << std::endl;
1284 }
1285 
1286 
1288 
1289 
1290 template<typename GridType>
1291 inline typename GridType::Ptr
1292 createGrid(const typename GridType::ValueType& background)
1293 {
1294  return GridType::create(background);
1295 }
1296 
1297 
1298 template<typename GridType>
1299 inline typename GridType::Ptr
1301 {
1302  return GridType::create();
1303 }
1304 
1305 
1306 template<typename TreePtrType>
1308 createGrid(TreePtrType tree)
1309 {
1310  typedef typename TreePtrType::element_type TreeType;
1311  return Grid<TreeType>::create(tree);
1312 }
1313 
1314 
1315 template<typename GridType>
1316 typename GridType::Ptr
1317 createLevelSet(Real voxelSize, Real halfWidth)
1318 {
1319  typedef typename GridType::ValueType ValueType;
1320 
1321  // GridType::ValueType is required to be a floating-point scalar.
1322  BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
1323 
1324  typename GridType::Ptr grid = GridType::create(
1325  /*background=*/static_cast<ValueType>(voxelSize * halfWidth));
1326  grid->setTransform(math::Transform::createLinearTransform(voxelSize));
1327  grid->setGridClass(GRID_LEVEL_SET);
1328  return grid;
1329 }
1330 
1331 } // namespace OPENVDB_VERSION_NAME
1332 } // namespace openvdb
1333 
1334 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
1335 
1336 // Copyright (c) 2012-2013 DreamWorks Animation LLC
1337 // All rights reserved. This software is distributed under the
1338 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
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:1170
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:933
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:268
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:187
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:851
virtual void pruneGrid(float tolerance=0.0)
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1153
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:978
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:439
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:403
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1199
Name name
Definition: Grid.h:422
Definition: Types.h:372
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:906
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:587
virtual void clear()
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:562
void setBackground(const ValueType &val)
Replace this grid's background value.
Definition: Grid.h:557
boost::shared_ptr< const Transform > ConstPtr
Definition: Transform.h:69
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1161
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:888
virtual Name type() const
Return the name of this grid's type.
Definition: Grid.h:543
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:856
TreeType::ValueType ValueType
Definition: Grid.h:849
boost::shared_ptr< const TreeBase > ConstPtr
Definition: Tree.h:68
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:822
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...
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:313
_TreeType TreeType
Definition: Grid.h:464
VecType
Definition: Types.h:198
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:796
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:921
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:780
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:870
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:989
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:1188
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:397
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:413
static const TreeType & tree(const GridType &g)
Definition: Grid.h:917
static TreeType & tree(GridType &g)
Definition: Grid.h:914
GridBase(const GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:380
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:588
static TreeType & tree(TreeType &t)
Definition: Grid.h:913
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:336
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:175
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:955
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:273
ValueConverter::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:486
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:338
MergePolicy
Definition: Types.h:221
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:145
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:752
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:555
boost::shared_ptr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:414
MetadataMap::const_iterator ConstMetaIterator
Definition: MetaMap.h:56
_TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:477
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:398
tree::ValueAccessor< _TreeType > Accessor
Definition: Grid.h:469
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:710
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:916
boost::shared_ptr< MetaMap > Ptr
Definition: MetaMap.h:51
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:176
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:1241
boost::shared_ptr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:409
virtual Index64 activeVoxelCount() const
Return the number of active voxels.
Definition: Grid.h:683
static const TreeType & constTree(GridType &g)
Definition: Grid.h:920
static TreeType & tree(TreeType &t)
Definition: Grid.h:884
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:922
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:402
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
Definition: Exceptions.h:88
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:581
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:837
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:872
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:701
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:271
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:702
boost::shared_ptr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:399
GridType::Ptr GridPtrType
Definition: Grid.h:876
Definition: Types.h:372
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:1102
Grid< typename TreeType::template ValueConverter< OtherValueType >::Type > Type
Definition: Grid.h:487
Abstract base class for typed grids.
Definition: Grid.h:103
GridClass
Definition: Types.h:168
_TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:472
boost::shared_ptr< Grid > Ptr
Definition: Grid.h:461
static const TreeType & tree(const GridType &g)
Definition: Grid.h:857
Definition: Types.h:170
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:858
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:711
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:918
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:754
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:412
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:845
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:971
Definition: ValueAccessor.h:173
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1292
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:880
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1043
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:842
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:1137
static const char *const META_VECTOR_TYPE
Definition: Grid.h:270
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:882
Definition: Exceptions.h:87
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:843
virtual void newTree()
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1126
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:703
uint64_t Index64
Definition: Types.h:56
#define OPENVDB_VERSION_NAME
Definition: version.h:45
virtual void setTree(TreeBase::Ptr)
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1113
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:881
virtual Coord evalActiveVoxelDim() const
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1217
static Transform::Ptr createLinearTransform(double voxelSize=1.0)
Create and return a shared pointer to a new transform.
virtual GridBase::Ptr deepCopyGrid() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:539
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:877
static const TreeType & tree(const GridType &g)
Definition: Grid.h:887
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:314
Grid< TreeType > GridType
Definition: Grid.h:844
CopyPolicy
Definition: Types.h:372
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 ...
_TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:476
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:847
virtual ~Grid()
Definition: Grid.h:525
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:899
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
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:609
virtual void writeBuffers(std::ostream &) const
Write out all data buffers for this grid.
Definition: Grid.h:1257
TreeType::ValueType ValueType
Definition: Grid.h:879
virtual void readBuffers(std::istream &)
Read all data buffers for this grid.
Definition: Grid.h:1249
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:750
virtual Name valueType() const
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:552
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
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:565
TreeType::Ptr TreePtrType
Definition: Grid.h:871
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:401
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:377
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:1233
virtual bool empty() const
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:560
Base class for typed trees.
Definition: Tree.h:64
static const char *const META_GRID_CLASS
Definition: Grid.h:265
static const char *const META_GRID_CREATOR
Definition: Grid.h:266
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:852
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:323
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:366
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:269
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:545
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:850
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:1179
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:418
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:576
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:886
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:396
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:582
TreeType::Ptr TreePtrType
Definition: Grid.h:841
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:174
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:624
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:364
_TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:475
Provides functionality storing type agnostic metadata information. Grids and other structures can inh...
Definition: MetaMap.h:48
boost::shared_ptr< const Grid > ConstPtr
Definition: Grid.h:462
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:408
static TreeType & tree(GridType &g)
Definition: Grid.h:855
Grid< TreeType > GridType
Definition: Grid.h:874
tree::TreeBase TreeBase
Definition: Grid.h:52
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:342
Vec3< double > Vec3d
Definition: Vec3.h:625
static TreeType & tree(AccessorType &a)
Definition: Grid.h:915
Definition: Types.h:372
virtual ~GridBase()
Definition: Grid.h:112
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:840
static TreeType & tree(TreeType &t)
Definition: Grid.h:854
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1308
virtual CoordBBox evalActiveVoxelBoundingBox() const
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1207
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:333
_TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:466
static const char *const META_GRID_NAME
Definition: Grid.h:267
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:907
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:910
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:901
tree::ValueAccessor< const _TreeType > ConstAccessor
Definition: Grid.h:470
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
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:1317
double Real
Definition: Types.h:63
_TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:473
static TreeType & tree(GridType &g)
Definition: Grid.h:885
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:875
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:860
GridType::Ptr GridPtrType
Definition: Grid.h:846
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:374
_TreeType::Ptr TreePtrType
Definition: Grid.h:465
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:406
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:272
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:275
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const
Output a human-readable description of this grid.
Definition: Grid.h:1265
TreeType & tree() const
Return a reference to the tree associated with this accessor.
Definition: ValueAccessor.h:117
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:407
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:322
_TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:474
_TreeType TreeType
Definition: Grid.h:869
boost::shared_ptr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:404
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:1081
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
TreeType::ValueType ValueType
Definition: Grid.h:908
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:421
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:712
GridNamePred(const Name &_name)
Definition: Grid.h:420
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:873
static const TreeType & constTree(GridType &g)
Definition: Grid.h:889
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:890
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:411
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:569
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:575
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:861
static const TreeType & constTree(GridType &g)
Definition: Grid.h:859
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:891
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:878
virtual Index64 memUsage() const
Definition: Grid.h:691
_TreeType::ValueType ValueType
Definition: Grid.h:467
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:919
Definition: Types.h:377
boost::shared_ptr< Transform > Ptr
Definition: Transform.h:68
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:911
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:904
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:848
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
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:902
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
std::string Name
Definition: Name.h:44
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:909
Calculate an axis-aligned bounding box in index space from a bounding sphere in world space...
Definition: Transform.h:65
_TreeType TreeType
Definition: Grid.h:839