31 #ifndef OPENVDB_GRID_HAS_BEEN_INCLUDED 32 #define OPENVDB_GRID_HAS_BEEN_INCLUDED 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> 54 template<
typename>
class Grid;
61 template<
typename Gr
idType>
62 inline typename GridType::Ptr
createGrid(
const typename GridType::ValueType& background);
68 template<
typename Gr
idType>
76 template<
typename TreePtrType>
94 template<
typename Gr
idType>
106 typedef boost::shared_ptr<GridBase>
Ptr;
107 typedef boost::shared_ptr<const GridBase>
ConstPtr;
109 typedef Ptr (*GridFactory)();
129 static bool isRegistered(
const Name &type);
132 static void clearRegistry();
139 virtual Name type()
const = 0;
141 virtual Name valueType()
const = 0;
144 template<
typename Gr
idType>
145 bool isType()
const {
return (this->type() == GridType::gridType()); }
148 template<
typename Gr
idType>
152 template<
typename Gr
idType>
154 template<
typename Gr
idType>
155 static typename GridType::ConstPtr constGrid(
const GridBase::Ptr&);
156 template<
typename Gr
idType>
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()); }
186 virtual void newTree() = 0;
189 virtual bool empty()
const = 0;
191 virtual void clear() = 0;
198 virtual void pruneGrid(
float tolerance = 0.0) = 0;
200 #ifndef OPENVDB_2_ABI_COMPATIBLE 201 void clipGrid(
const BBoxd&);
211 virtual void clip(
const CoordBBox&) = 0;
219 std::string getName()
const;
221 void setName(
const std::string&);
224 std::string getCreator()
const;
226 void setCreator(
const std::string&);
230 bool saveFloatAsHalf()
const;
231 void setSaveFloatAsHalf(
bool);
238 void clearGridClass();
241 static std::string gridClassToString(
GridClass);
243 static std::string gridClassToMenuName(
GridClass);
247 static GridClass stringToGridClass(
const std::string&);
256 void clearVectorType();
259 static std::string vecTypeToString(
VecType);
262 static std::string vecTypeExamples(
VecType);
265 static std::string vecTypeDescription(
VecType);
266 static VecType stringToVecType(
const std::string&);
271 bool isInWorldSpace()
const;
273 void setIsInWorldSpace(
bool);
296 virtual Index64 activeVoxelCount()
const = 0;
300 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
303 virtual Coord evalActiveVoxelDim()
const = 0;
306 virtual Index64 memUsage()
const = 0;
312 void addStatsMetadata();
354 Vec3d indexToWorld(
const Vec3d& xyz)
const {
return transform().indexToWorld(xyz); }
358 Vec3d worldToIndex(
const Vec3d& xyz)
const {
return transform().worldToIndex(xyz); }
367 virtual void readTopology(std::istream&) = 0;
370 virtual void writeTopology(std::ostream&)
const = 0;
373 virtual void readBuffers(std::istream&) = 0;
374 #ifndef OPENVDB_2_ABI_COMPATIBLE 375 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
382 virtual void readNonresidentBuffers()
const = 0;
384 virtual void writeBuffers(std::ostream&)
const = 0;
393 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
398 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
407 static void registerGrid(
const Name& type, GridFactory);
409 static void unregisterGrid(
const Name& type);
450 template<
typename Gr
idPtrContainerT>
451 inline typename GridPtrContainerT::value_type
454 typedef typename GridPtrContainerT::value_type GridPtrT;
455 typename GridPtrContainerT::const_iterator it =
456 std::find_if(container.begin(), container.end(),
GridNamePred(name));
457 return (it == container.end() ? GridPtrT() : *it);
461 template<
typename KeyT,
typename Gr
idPtrT>
465 typedef std::map<KeyT, GridPtrT> GridPtrMapT;
466 for (
typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
469 const GridPtrT& grid = it->second;
470 if (grid && grid->getName() == name)
return grid;
481 template<
typename _TreeType>
485 typedef boost::shared_ptr<Grid>
Ptr;
511 template<
typename OtherValueType>
517 static Ptr create(
const ValueType& background);
522 static Ptr create(TreePtrType);
525 static Ptr create(
const GridBase& other);
531 explicit Grid(
const ValueType& background);
535 explicit Grid(TreePtrType);
543 template<
typename OtherTreeType>
563 Ptr deepCopy()
const {
return Ptr(
new Grid(*
this)); }
569 virtual Name type()
const {
return this->gridType(); }
583 const ValueType&
background()
const {
return mTree->background(); }
586 virtual bool empty()
const {
return tree().empty(); }
588 virtual void clear() { tree().clear(); }
604 ConstAccessor getAccessor()
const {
return ConstAccessor(tree()); }
608 ConstAccessor getConstUnsafeAccessor()
const {
return ConstUnsafeAccessor(tree()); }
619 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
625 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
631 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
638 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
648 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
651 virtual void pruneGrid(
float tolerance = 0.0);
653 #ifndef OPENVDB_2_ABI_COMPATIBLE 654 virtual void clip(
const CoordBBox&);
681 template<
typename OtherTreeType>
696 template<
typename OtherTreeType>
709 template<
typename OtherTreeType>
718 virtual CoordBBox evalActiveVoxelBoundingBox()
const;
720 virtual Coord evalActiveVoxelDim()
const;
731 TreePtrType treePtr() {
return mTree; }
734 ConstTreePtrType
treePtr()
const {
return mTree; }
739 TreeType& tree() {
return *mTree; }
744 const TreeType&
tree()
const {
return *mTree; }
757 virtual void newTree();
765 virtual void readTopology(std::istream&);
768 virtual void writeTopology(std::ostream&)
const;
771 virtual void readBuffers(std::istream&);
772 #ifndef OPENVDB_2_ABI_COMPATIBLE 773 virtual void readBuffers(std::istream&,
const CoordBBox&);
780 virtual void readNonresidentBuffers()
const;
782 virtual void writeBuffers(std::ostream&)
const;
786 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const;
821 template<
typename Gr
idType>
822 inline typename GridType::Ptr
825 return GridBase::grid<GridType>(grid);
837 template<
typename Gr
idType>
838 inline typename GridType::ConstPtr
841 return GridBase::constGrid<GridType>(grid);
854 template<
typename Gr
idType>
855 inline typename GridType::Ptr
858 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
859 return gridPtrCast<GridType>(grid->deepCopyGrid());
863 template<
typename Gr
idType>
864 inline typename GridType::Ptr
867 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
877 template<
typename _TreeType>
897 static TreeType&
tree(TreeType& t) {
return t; }
898 static TreeType&
tree(GridType& g) {
return g.
tree(); }
899 static const TreeType&
tree(
const TreeType& t) {
return t; }
900 static const TreeType&
tree(
const GridType& g) {
return g.
tree(); }
901 static const TreeType&
constTree(TreeType& t) {
return t; }
903 static const TreeType&
constTree(
const TreeType& t) {
return t; }
909 template<
typename _TreeType>
927 static TreeType&
tree(TreeType& t) {
return t; }
928 static TreeType&
tree(GridType& g) {
return g.
tree(); }
929 static const TreeType&
tree(
const TreeType& t) {
return t; }
930 static const TreeType&
tree(
const GridType& g) {
return g.
tree(); }
931 static const TreeType&
constTree(TreeType& t) {
return t; }
933 static const TreeType&
constTree(
const TreeType& t) {
return t; }
938 template<
typename _TreeType>
956 static TreeType&
tree(TreeType& t) {
return t; }
957 static TreeType&
tree(GridType& g) {
return g.
tree(); }
958 static TreeType&
tree(AccessorType& a) {
return a.
tree(); }
959 static const TreeType&
tree(
const TreeType& t) {
return t; }
960 static const TreeType&
tree(
const GridType& g) {
return g.
tree(); }
961 static const TreeType&
tree(
const AccessorType& a) {
return a.
tree(); }
962 static const TreeType&
constTree(TreeType& t) {
return t; }
964 static const TreeType&
constTree(
const TreeType& t) {
return t; }
974 template<
typename Gr
idType>
980 if (grid && grid->type() == GridType::gridType()) {
981 return boost::static_pointer_cast<GridType>(grid);
983 return typename GridType::Ptr();
987 template<
typename Gr
idType>
988 inline typename GridType::ConstPtr
991 return boost::const_pointer_cast<
const GridType>(
992 GridBase::grid<GridType>(boost::const_pointer_cast<
GridBase>(grid)));
996 template<
typename Gr
idType>
997 inline typename GridType::ConstPtr
1000 return boost::const_pointer_cast<
const GridType>(GridBase::grid<GridType>(grid));
1004 template<
typename Gr
idType>
1005 inline typename GridType::ConstPtr
1008 return boost::const_pointer_cast<
const GridType>(
1009 GridBase::grid<GridType>(boost::const_pointer_cast<
GridBase>(grid)));
1016 return boost::const_pointer_cast<TreeBase>(this->constBaseTreePtr());
1031 template<
typename TreeT>
1037 template<
typename TreeT>
1043 template<
typename TreeT>
1050 template<
typename TreeT>
1053 mTree(boost::static_pointer_cast<
TreeType>(other.mTree->
copy()))
1058 template<
typename TreeT>
1059 template<
typename OtherTreeType>
1067 template<
typename TreeT>
1075 template<
typename TreeT>
1084 template<
typename TreeT>
1093 template<
typename TreeT>
1097 return Ptr(
new Grid(background));
1102 template<
typename TreeT>
1111 template<
typename TreeT>
1122 template<
typename TreeT>
1127 switch (treePolicy) {
1133 ret.reset(
new Grid(*
this));
1143 template<
typename TreeT>
1147 return this->
copy(treePolicy);
1154 template<
typename TreeT>
1159 if (tree->type() != TreeType::treeType()) {
1161 + tree->type() +
" to a grid of type " + this->
type());
1167 template<
typename TreeT>
1178 template<
typename TreeT>
1182 tree().fill(bbox, value, active);
1185 template<
typename TreeT>
1189 this->
tree().prune(
ValueType(zeroVal<ValueType>() + tolerance));
1192 #ifndef OPENVDB_2_ABI_COMPATIBLE 1193 template<
typename TreeT>
1202 template<
typename TreeT>
1206 tree().merge(other.
tree(), policy);
1210 template<
typename TreeT>
1211 template<
typename OtherTreeType>
1215 tree().topologyUnion(other.
tree());
1219 template<
typename TreeT>
1220 template<
typename OtherTreeType>
1224 tree().topologyIntersection(other.
tree());
1228 template<
typename TreeT>
1229 template<
typename OtherTreeType>
1233 tree().topologyDifference(other.
tree());
1240 template<
typename TreeT>
1244 tree().evalMinMax(minVal, maxVal);
1248 template<
typename TreeT>
1253 tree().evalActiveVoxelBoundingBox(bbox);
1258 template<
typename TreeT>
1263 const bool nonempty =
tree().evalActiveVoxelDim(dim);
1264 return (nonempty ? dim : Coord());
1274 template<
typename TreeT>
1282 template<
typename TreeT>
1290 template<
typename TreeT>
1298 #ifndef OPENVDB_2_ABI_COMPATIBLE 1300 template<
typename TreeT>
1308 template<
typename TreeT>
1312 tree().readNonresidentBuffers();
1315 #endif // !OPENVDB_2_ABI_COMPATIBLE 1318 template<
typename TreeT>
1326 template<
typename TreeT>
1330 tree().print(os, verboseLevel);
1333 os <<
"Additional metadata:" << std::endl;
1335 os <<
" " << it->first;
1337 const std::string value = it->second->str();
1338 if (!value.empty()) os <<
": " << value;
1344 os <<
"Transform:" << std::endl;
1353 template<
typename Gr
idType>
1354 inline typename GridType::Ptr
1357 return GridType::create(background);
1361 template<
typename Gr
idType>
1362 inline typename GridType::Ptr
1365 return GridType::create();
1369 template<
typename TreePtrType>
1373 typedef typename TreePtrType::element_type
TreeType;
1378 template<
typename Gr
idType>
1379 typename GridType::Ptr
1382 typedef typename GridType::ValueType
ValueType;
1385 BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
1387 typename GridType::Ptr
grid = GridType::create(
1388 static_cast<ValueType>(voxelSize * halfWidth));
1397 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED static const TreeType & tree(const GridType &g)
Definition: Grid.h:930
GridType::ConstPtr gridConstPtrCast(const GridBase::ConstPtr &grid)
Cast a generic const grid pointer to a const pointer to a grid of a concrete class.
Definition: Grid.h:839
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:893
_TreeType TreeType
Definition: Grid.h:488
static TreeType & tree(GridType &g)
Definition: Grid.h:957
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:895
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:921
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:961
static TreeType & tree(AccessorType &a)
Definition: Grid.h:958
static TreeType & tree(TreeType &t)
Definition: Grid.h:956
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:633
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels. The accessor is safe in the sense that it is registered by the tree of this grid.
Definition: Grid.h:593
virtual void clear()
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:588
boost::shared_ptr< const TreeBase > ConstPtr
Definition: Tree.h:67
TreeType::ValueType ValueType
Definition: Grid.h:922
virtual bool empty() const
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:586
virtual void readTopology(std::istream &)
Read the grid topology from a stream. This will read only the grid structure, not the actual data buf...
Definition: Grid.h:1276
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:175
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:923
TreeType::Ptr TreePtrType
Definition: Grid.h:884
GridType::Ptr createLevelSet(Real voxelSize=1.0, Real halfWidth=LEVEL_SET_HALF_WIDTH)
Create a new grid of type GridType classified as a "Level Set", i.e., a narrow-band level set...
Definition: Grid.h:1380
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:944
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:931
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:1222
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:427
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:915
virtual Index64 memUsage() const
Definition: Grid.h:724
Abstract base class for typed grids.
Definition: Grid.h:103
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:950
GridType::Ptr gridPtrCast(const GridBase::Ptr &grid)
Cast a generic grid pointer to a pointer to a grid of a concrete class.
Definition: Grid.h:823
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:583
static const char *const META_GRID_CREATOR
Definition: Grid.h:280
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:744
tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:500
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:952
Name name
Definition: Grid.h:446
Definition: Exceptions.h:88
virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy=CP_SHARE) const
Return a new grid of the same type as this grid and whose metadata and transform are deep copies of t...
Definition: Grid.h:1145
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:327
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:1231
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:145
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
MergePolicy
Definition: Types.h:257
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1242
virtual Name type() const
Return the name of this grid's type.
Definition: Grid.h:569
TreeType & tree() const
Return a reference to the tree associated with this accessor.
Definition: ValueAccessor.h:147
virtual void writeTopology(std::ostream &) const
Write the grid topology to a stream. This will write only the grid structure, not the actual data buf...
Definition: Grid.h:1284
TreeBase::ConstPtr baseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:164
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const
Output a human-readable description of this grid.
Definition: Grid.h:1328
static TreeType & tree(GridType &g)
Definition: Grid.h:928
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:347
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:436
static const char *const META_GRID_CLASS
Definition: Grid.h:279
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:924
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:916
GridType::Ptr GridPtrType
Definition: Grid.h:919
_TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:496
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:390
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:913
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:964
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:285
boost::shared_ptr< TreeBase > Ptr
Definition: Tree.h:66
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:743
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:422
ConstTreePtrType constTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:735
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:174
static TreeType & tree(TreeType &t)
Definition: Grid.h:927
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:945
GridBase(const GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:404
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:435
Grid< TreeType > GridType
Definition: Grid.h:946
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:289
static const char *const META_VECTOR_TYPE
Definition: Grid.h:284
_TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:495
_TreeType::Ptr TreePtrType
Definition: Grid.h:489
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:287
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
Definition: Grid.h:998
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:336
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:283
tree::TreeBase TreeBase
Definition: Grid.h:52
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1032
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:904
GridType::Ptr GridPtrType
Definition: Grid.h:889
virtual TreeBase::ConstPtr constBaseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:736
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:934
Base class for typed trees.
Definition: Tree.h:63
boost::shared_ptr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:438
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:426
boost::shared_ptr< Grid > Ptr
Definition: Grid.h:485
virtual void readNonresidentBuffers() const
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
Definition: Grid.h:1310
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1204
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:401
_TreeType TreeType
Definition: Grid.h:941
GridClass
Definition: Types.h:204
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
_TreeType TreeType
Definition: Grid.h:912
ConstTreePtrType treePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:734
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1086
virtual Index64 activeVoxelCount() const
Return the number of active voxels.
Definition: Grid.h:716
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:918
tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:503
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:925
TreeType::ValueType ValueType
Definition: Grid.h:951
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1021
_TreeType TreeType
Definition: Grid.h:882
#define OPENVDB_VERSION_NAME
Definition: version.h:43
_TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:493
virtual void setTree(TreeBase::Ptr)
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1156
static TreeType & tree(GridType &g)
Definition: Grid.h:898
virtual ~GridBase()
Definition: Grid.h:112
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:888
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:606
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:634
_TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:494
GridPtrT findGridByName(const std::map< KeyT, GridPtrT > &container, const Name &name)
Return the first grid in the given map whose name is name.
Definition: Grid.h:463
tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:502
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:891
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:432
TreeType::Ptr TreePtrType
Definition: Grid.h:914
static GridType::Ptr grid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
Definition: Grid.h:976
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:962
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:442
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:282
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:512
VecType
Definition: Types.h:234
OPENVDB_API uint32_t getGridClass(std::ios_base &)
Return the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently being read from or writte...
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:352
virtual void writeBuffers(std::ostream &) const
Write out all data buffers for this grid.
Definition: Grid.h:1320
virtual Name valueType() const
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:578
virtual Coord evalActiveVoxelDim() const
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1260
virtual GridBase::Ptr deepCopyGrid() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:565
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
Grid< TreeType > GridType
Definition: Grid.h:887
static const TreeType & constTree(GridType &g)
Definition: Grid.h:932
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
std::string Name
Definition: Name.h:44
_TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:497
Definition: Exceptions.h:39
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:899
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:797
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:920
static const char *const META_GRID_NAME
Definition: Grid.h:281
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:953
GridType::Ptr GridPtrType
Definition: Grid.h:948
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:929
Accessor getUnsafeAccessor()
Return an accessor that provides random read and write access to this grid's voxels. The accessor is unsafe in the sense that it is not registered by the tree of this grid. In some rare cases this can give a performance advantage over a registered accessor but it is unsafe if the tree topology is modified.
Definition: Grid.h:602
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:954
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:947
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:880
boost::shared_ptr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:433
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:903
Vec3< double > Vec3d
Definition: Vec3.h:643
boost::shared_ptr< const Grid > ConstPtr
Definition: Grid.h:486
TreeType::ValueType ValueType
Definition: Grid.h:892
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:959
boost::shared_ptr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:423
_TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:498
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:622
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:328
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:965
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
void topologyUnion(const Grid< OtherTreeType > &other)
Union this grid's set of active values with the active values of the other grid, whose value type may...
Definition: Grid.h:1213
Ptr copy(CopyPolicy treePolicy=CP_SHARE) const
Return a new grid of the same type as this grid and whose metadata and transform are deep copies of t...
Definition: Grid.h:1124
_TreeType::ValueType ValueType
Definition: Grid.h:491
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:745
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:420
double Real
Definition: Types.h:64
virtual void pruneGrid(float tolerance=0.0)
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1187
static const TreeType & tree(const GridType &g)
Definition: Grid.h:960
_TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:490
Definition: ValueAccessor.h:219
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:571
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:425
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:621
static TreeType & tree(TreeType &t)
Definition: Grid.h:897
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:388
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:350
uint64_t Index64
Definition: Types.h:57
CopyPolicy
Definition: Types.h:411
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:288
static const TreeType & constTree(GridType &g)
Definition: Grid.h:902
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition: Grid.h:1180
virtual void clip(const CoordBBox &)
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1195
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:398
virtual void newTree()
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1169
tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:501
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:901
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:286
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1371
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:430
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:437
virtual ~Grid()
Definition: Grid.h:551
Grid< TreeType > GridType
Definition: Grid.h:917
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:885
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:883
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:793
TreeBase::Ptr baseTreePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:1014
virtual void readBuffers(std::istream &)
Read all data buffers for this grid.
Definition: Grid.h:1292
OPENVDB_API void setGridClass(std::ios_base &, uint32_t)
Associate with the given stream the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently ...
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:886
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:431
GridType::Ptr deepCopyTypedGrid(const GridBase &grid)
Return a pointer to a deep copy of the given grid, provided that the grid's concrete type is GridType...
Definition: Grid.h:865
boost::shared_ptr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:428
Definition: Exceptions.h:87
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:942
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:335
virtual CoordBBox evalActiveVoxelBoundingBox() const
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1250
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:949
static const TreeType & tree(const GridType &g)
Definition: Grid.h:900
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:795
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:421
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:627
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:212
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:890
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:894
static const TreeType & constTree(GridType &g)
Definition: Grid.h:963
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:337
TreeType::Ptr TreePtrType
Definition: Grid.h:943
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:445
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:628
GridNamePred(const Name &_name)
Definition: Grid.h:444
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:933
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:356
Grid< typename TreeType::template ValueConverter< OtherValueType >::Type > Type
Definition: Grid.h:513