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;
509 template<
typename OtherValueType>
515 static Ptr create(
const ValueType& background);
520 static Ptr create(TreePtrType);
523 static Ptr create(
const GridBase& other);
529 explicit Grid(
const ValueType& background);
533 explicit Grid(TreePtrType);
541 template<
typename OtherTreeType>
561 Ptr deepCopy()
const {
return Ptr(
new Grid(*
this)); }
567 virtual Name type()
const {
return this->gridType(); }
581 const ValueType&
background()
const {
return mTree->background(); }
584 virtual bool empty()
const {
return tree().empty(); }
586 virtual void clear() { tree().clear(); }
591 ConstAccessor getAccessor()
const {
return ConstAccessor(tree()); }
597 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
603 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
609 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
616 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
626 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
629 virtual void pruneGrid(
float tolerance = 0.0);
631 #ifndef OPENVDB_2_ABI_COMPATIBLE
632 virtual void clip(
const CoordBBox&);
659 template<
typename OtherTreeType>
674 template<
typename OtherTreeType>
687 template<
typename OtherTreeType>
696 virtual CoordBBox evalActiveVoxelBoundingBox()
const;
698 virtual Coord evalActiveVoxelDim()
const;
709 TreePtrType treePtr() {
return mTree; }
712 ConstTreePtrType
treePtr()
const {
return mTree; }
717 TreeType& tree() {
return *mTree; }
722 const TreeType&
tree()
const {
return *mTree; }
735 virtual void newTree();
743 virtual void readTopology(std::istream&);
746 virtual void writeTopology(std::ostream&)
const;
749 virtual void readBuffers(std::istream&);
750 #ifndef OPENVDB_2_ABI_COMPATIBLE
751 virtual void readBuffers(std::istream&,
const CoordBBox&);
758 virtual void readNonresidentBuffers()
const;
760 virtual void writeBuffers(std::ostream&)
const;
764 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const;
799 template<
typename Gr
idType>
800 inline typename GridType::Ptr
803 return GridBase::grid<GridType>(grid);
815 template<
typename Gr
idType>
816 inline typename GridType::ConstPtr
819 return GridBase::constGrid<GridType>(grid);
832 template<
typename Gr
idType>
833 inline typename GridType::Ptr
836 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
837 return gridPtrCast<GridType>(grid->deepCopyGrid());
841 template<
typename Gr
idType>
842 inline typename GridType::Ptr
845 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
855 template<
typename _TreeType>
875 static TreeType&
tree(TreeType& t) {
return t; }
876 static TreeType&
tree(GridType& g) {
return g.
tree(); }
877 static const TreeType&
tree(
const TreeType& t) {
return t; }
878 static const TreeType&
tree(
const GridType& g) {
return g.
tree(); }
879 static const TreeType&
constTree(TreeType& t) {
return t; }
881 static const TreeType&
constTree(
const TreeType& t) {
return t; }
887 template<
typename _TreeType>
905 static TreeType&
tree(TreeType& t) {
return t; }
906 static TreeType&
tree(GridType& g) {
return g.
tree(); }
907 static const TreeType&
tree(
const TreeType& t) {
return t; }
908 static const TreeType&
tree(
const GridType& g) {
return g.
tree(); }
909 static const TreeType&
constTree(TreeType& t) {
return t; }
911 static const TreeType&
constTree(
const TreeType& t) {
return t; }
916 template<
typename _TreeType>
934 static TreeType&
tree(TreeType& t) {
return t; }
935 static TreeType&
tree(GridType& g) {
return g.
tree(); }
936 static TreeType&
tree(AccessorType& a) {
return a.
tree(); }
937 static const TreeType&
tree(
const TreeType& t) {
return t; }
938 static const TreeType&
tree(
const GridType& g) {
return g.
tree(); }
939 static const TreeType&
tree(
const AccessorType& a) {
return a.
tree(); }
940 static const TreeType&
constTree(TreeType& t) {
return t; }
942 static const TreeType&
constTree(
const TreeType& t) {
return t; }
952 template<
typename Gr
idType>
953 inline typename GridType::Ptr
958 if (grid && grid->type() == GridType::gridType()) {
959 return boost::static_pointer_cast<GridType>(grid);
961 return typename GridType::Ptr();
965 template<
typename Gr
idType>
966 inline typename GridType::ConstPtr
969 return boost::const_pointer_cast<
const GridType>(
970 GridBase::grid<GridType>(boost::const_pointer_cast<
GridBase>(grid)));
974 template<
typename Gr
idType>
975 inline typename GridType::ConstPtr
978 return boost::const_pointer_cast<
const GridType>(GridBase::grid<GridType>(grid));
982 template<
typename Gr
idType>
983 inline typename GridType::ConstPtr
986 return boost::const_pointer_cast<
const GridType>(
987 GridBase::grid<GridType>(boost::const_pointer_cast<
GridBase>(grid)));
994 return boost::const_pointer_cast<TreeBase>(this->constBaseTreePtr());
1009 template<
typename TreeT>
1015 template<
typename TreeT>
1021 template<
typename TreeT>
1028 template<
typename TreeT>
1031 mTree(boost::static_pointer_cast<TreeType>(other.mTree->copy()))
1036 template<
typename TreeT>
1037 template<
typename OtherTreeType>
1040 mTree(new TreeType(other.constTree()))
1045 template<
typename TreeT>
1053 template<
typename TreeT>
1062 template<
typename TreeT>
1071 template<
typename TreeT>
1075 return Ptr(
new Grid(background));
1080 template<
typename TreeT>
1084 return Ptr(
new Grid(tree));
1089 template<
typename TreeT>
1093 return Ptr(
new Grid(other));
1100 template<
typename TreeT>
1105 switch (treePolicy) {
1111 ret.reset(
new Grid(*
this));
1121 template<
typename TreeT>
1125 return this->copy(treePolicy);
1132 template<
typename TreeT>
1137 if (tree->type() != TreeType::treeType()) {
1139 + tree->type() +
" to a grid of type " + this->type());
1141 mTree = boost::static_pointer_cast<TreeType>(tree);
1145 template<
typename TreeT>
1149 mTree.reset(
new TreeType(this->background()));
1156 template<
typename TreeT>
1160 tree().fill(bbox, value, active);
1163 template<
typename TreeT>
1167 this->tree().prune(ValueType(zeroVal<ValueType>() + tolerance));
1170 #ifndef OPENVDB_2_ABI_COMPATIBLE
1171 template<
typename TreeT>
1180 template<
typename TreeT>
1184 tree().merge(other.
tree(), policy);
1188 template<
typename TreeT>
1189 template<
typename OtherTreeType>
1193 tree().topologyUnion(other.
tree());
1197 template<
typename TreeT>
1198 template<
typename OtherTreeType>
1202 tree().topologyIntersection(other.
tree());
1206 template<
typename TreeT>
1207 template<
typename OtherTreeType>
1211 tree().topologyDifference(other.
tree());
1218 template<
typename TreeT>
1222 tree().evalMinMax(minVal, maxVal);
1226 template<
typename TreeT>
1231 tree().evalActiveVoxelBoundingBox(bbox);
1236 template<
typename TreeT>
1241 const bool nonempty = tree().evalActiveVoxelDim(dim);
1242 return (nonempty ? dim : Coord());
1252 template<
typename TreeT>
1256 tree().readTopology(is, saveFloatAsHalf());
1260 template<
typename TreeT>
1264 tree().writeTopology(os, saveFloatAsHalf());
1268 template<
typename TreeT>
1272 tree().readBuffers(is, saveFloatAsHalf());
1276 #ifndef OPENVDB_2_ABI_COMPATIBLE
1278 template<
typename TreeT>
1282 tree().readBuffers(is, bbox, saveFloatAsHalf());
1286 template<
typename TreeT>
1290 tree().readNonresidentBuffers();
1293 #endif // !OPENVDB_2_ABI_COMPATIBLE
1296 template<
typename TreeT>
1300 tree().writeBuffers(os, saveFloatAsHalf());
1304 template<
typename TreeT>
1308 tree().print(os, verboseLevel);
1310 if (metaCount() > 0) {
1311 os <<
"Additional metadata:" << std::endl;
1313 os <<
" " << it->first;
1315 const std::string value = it->second->str();
1316 if (!value.empty()) os <<
": " << value;
1322 os <<
"Transform:" << std::endl;
1323 transform().print(os,
" ");
1331 template<
typename Gr
idType>
1332 inline typename GridType::Ptr
1335 return GridType::create(background);
1339 template<
typename Gr
idType>
1340 inline typename GridType::Ptr
1343 return GridType::create();
1347 template<
typename TreePtrType>
1351 typedef typename TreePtrType::element_type TreeType;
1356 template<
typename Gr
idType>
1357 typename GridType::Ptr
1360 typedef typename GridType::ValueType ValueType;
1363 BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
1365 typename GridType::Ptr grid = GridType::create(
1366 static_cast<ValueType>(voxelSize * halfWidth));
1375 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:606
GridNamePred(const Name &_name)
Definition: Grid.h:444
static const TreeType & tree(const GridType &g)
Definition: Grid.h:908
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:899
_TreeType TreeType
Definition: Grid.h:488
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:388
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:922
TreeType::ValueType ValueType
Definition: Grid.h:900
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:347
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:901
void topologyIntersection(const Grid< OtherTreeType > &other)
Intersect this grid's set of active values with the active values of the other grid, whose value type may be different.
Definition: Grid.h:1200
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:611
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:589
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:909
virtual void clear()
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:586
boost::shared_ptr< const TreeBase > ConstPtr
Definition: Tree.h:67
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:442
virtual bool empty() const
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:584
virtual void readTopology(std::istream &)
Read the grid topology from a stream. This will read only the grid structure, not the actual data buf...
Definition: Grid.h:1254
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:863
static TreeType & tree(AccessorType &a)
Definition: Grid.h:936
std::string Name
Definition: Name.h:44
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:869
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:893
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:864
virtual GridBase::Ptr copyGrid(CopyPolicy treePolicy=CP_SHARE) const
Return a new grid of the same type as this grid and whose metadata and transform are deep copies of t...
Definition: Grid.h:1123
_TreeType TreeType
Definition: Grid.h:919
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:445
virtual Index64 memUsage() const
Definition: Grid.h:702
Abstract base class for typed grids.
Definition: Grid.h:103
uint64_t Index64
Definition: Types.h:58
Grid< TreeType > GridType
Definition: Grid.h:865
OPENVDB_API uint32_t getGridClass(std::ios_base &)
Return the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently being read from or writte...
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:928
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:581
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:356
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:877
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:722
virtual Name type() const
Return the name of this grid's type.
Definition: Grid.h:567
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:920
Definition: ValueAccessor.h:173
virtual void writeTopology(std::ostream &) const
Write the grid topology to a stream. This will write only the grid structure, not the actual data buf...
Definition: Grid.h:1262
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:352
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:283
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1333
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const
Output a human-readable description of this grid.
Definition: Grid.h:1306
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:420
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
tree::ValueAccessor< const _TreeType > ConstAccessor
Definition: Grid.h:494
void topologyDifference(const Grid< OtherTreeType > &other)
Difference this grid's set of active values with the active values of the other grid, whose value type may be different.
Definition: Grid.h:1209
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
GridPtrT findGridByName(const std::map< KeyT, GridPtrT > &container, const Name &name)
Return the first grid in the given map whose name is name.
Definition: Grid.h:463
boost::shared_ptr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:423
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:437
static TreeType & tree(GridType &g)
Definition: Grid.h:906
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1220
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:894
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:425
GridType::Ptr GridPtrType
Definition: Grid.h:897
_TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:499
_TreeType TreeType
Definition: Grid.h:860
static const TreeType & constTree(GridType &g)
Definition: Grid.h:880
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:902
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:871
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:866
CopyPolicy
Definition: Types.h:416
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
boost::shared_ptr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:433
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:282
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:891
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:923
TreeType::ValueType ValueType
Definition: Grid.h:929
Grid< TreeType > GridType
Definition: Grid.h:924
double Real
Definition: Types.h:65
static TreeType & tree(TreeType &t)
Definition: Grid.h:905
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
_TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:498
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:930
_TreeType::Ptr TreePtrType
Definition: Grid.h:489
boost::shared_ptr< TreeBase > Ptr
Definition: Tree.h:66
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:721
ConstTreePtrType constTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:713
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:328
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:350
virtual TreeBase::ConstPtr constBaseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:714
TreeBase::Ptr baseTreePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:992
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:912
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:431
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1182
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:872
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1010
Name name
Definition: Grid.h:446
boost::shared_ptr< Grid > Ptr
Definition: Grid.h:485
virtual void readNonresidentBuffers() const
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
Definition: Grid.h:1288
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1064
virtual Index64 activeVoxelCount() const
Return the number of active voxels.
Definition: Grid.h:694
_TreeType TreeType
Definition: Grid.h:890
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:931
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:896
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:337
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:390
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:879
virtual void setTree(TreeBase::Ptr)
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1134
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:903
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:942
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:943
ConstTreePtrType treePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:712
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:612
#define OPENVDB_VERSION_NAME
Definition: version.h:43
_TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:497
OPENVDB_API void setGridClass(std::ios_base &, uint32_t)
Associate with the given stream the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently ...
_TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:496
static const char *const META_GRID_CREATOR
Definition: Grid.h:280
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:216
Definition: Exceptions.h:87
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1349
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:430
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:593
static const TreeType & tree(const GridType &g)
Definition: Grid.h:878
virtual void writeBuffers(std::ostream &) const
Write out all data buffers for this grid.
Definition: Grid.h:1298
TreeType::Ptr TreePtrType
Definition: Grid.h:892
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:932
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:925
_TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:500
boost::shared_ptr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:428
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:775
static const TreeType & constTree(GridType &g)
Definition: Grid.h:910
static TreeType & tree(TreeType &t)
Definition: Grid.h:875
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:898
Definition: Exceptions.h:39
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:907
virtual Name valueType() const
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:576
virtual Coord evalActiveVoxelDim() const
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1238
virtual GridBase::Ptr deepCopyGrid() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:563
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:937
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:421
static const TreeType & tree(const GridType &g)
Definition: Grid.h:938
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:336
Vec3< double > Vec3d
Definition: Vec3.h:629
virtual ~GridBase()
Definition: Grid.h:112
_TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:501
MergePolicy
Definition: Types.h:261
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:285
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:861
GridType::Ptr GridPtrType
Definition: Grid.h:926
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:288
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:927
boost::shared_ptr< const Grid > ConstPtr
Definition: Grid.h:486
GridBase(const GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:404
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:398
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:286
GridType::ConstPtr gridConstPtrCast(const GridBase::ConstPtr &grid)
Cast a generic const grid pointer to a const pointer to a grid of a concrete class.
Definition: Grid.h:817
GridType::Ptr gridPtrCast(const GridBase::Ptr &grid)
Cast a generic grid pointer to a pointer to a grid of a concrete class.
Definition: Grid.h:801
void topologyUnion(const Grid< OtherTreeType > &other)
Union this grid's set of active values with the active values of the other grid, whose value type may...
Definition: Grid.h:1191
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:287
Ptr copy(CopyPolicy treePolicy=CP_SHARE) const
Return a new grid of the same type as this grid and whose metadata and transform are deep copies of t...
Definition: Grid.h:1102
static TreeType & tree(GridType &g)
Definition: Grid.h:876
static GridType::Ptr grid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
Definition: Grid.h:954
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:940
tree::ValueAccessor< _TreeType > Accessor
Definition: Grid.h:493
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:600
_TreeType::ValueType ValueType
Definition: Grid.h:491
Definition: Exceptions.h:88
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:723
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:175
GridType::Ptr createLevelSet(Real voxelSize=1.0, Real halfWidth=LEVEL_SET_HALF_WIDTH)
Create a new grid of type GridType classified as a "Level Set", i.e., a narrow-band level set...
Definition: Grid.h:1358
boost::shared_ptr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:438
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:868
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:426
_TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:490
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:427
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:569
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:401
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:599
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:422
GridClass
Definition: Types.h:208
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:174
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:435
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:882
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:436
virtual void pruneGrid(float tolerance=0.0)
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1165
static TreeType & tree(TreeType &t)
Definition: Grid.h:934
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:873
tree::TreeBase TreeBase
Definition: Grid.h:52
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:999
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:327
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:858
virtual ~Grid()
Definition: Grid.h:549
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition: Grid.h:1158
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:881
TreeType::Ptr TreePtrType
Definition: Grid.h:862
virtual void clip(const CoordBBox &)
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1173
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:289
virtual void newTree()
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1147
virtual void readBuffers(std::istream &)
Read all data buffers for this grid.
Definition: Grid.h:1270
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
TreeType::ValueType ValueType
Definition: Grid.h:870
Grid< TreeType > GridType
Definition: Grid.h:895
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:432
static const char *const META_GRID_CLASS
Definition: Grid.h:279
virtual CoordBBox evalActiveVoxelBoundingBox() const
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1228
VecType
Definition: Types.h:238
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:771
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:145
Base class for typed trees.
Definition: Tree.h:63
GridType::Ptr deepCopyTypedGrid(const GridBase &grid)
Return a pointer to a deep copy of the given grid, provided that the grid's concrete type is GridType...
Definition: Grid.h:843
static const char *const META_GRID_NAME
Definition: Grid.h:281
TreeBase::ConstPtr baseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:164
static TreeType & tree(GridType &g)
Definition: Grid.h:935
TreeType::Ptr TreePtrType
Definition: Grid.h:921
GridType::Ptr GridPtrType
Definition: Grid.h:867
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:773
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:939
static const char *const META_VECTOR_TYPE
Definition: Grid.h:284
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:605
Grid< typename TreeType::template ValueConverter< OtherValueType >::Type > Type
Definition: Grid.h:511
TreeType & tree() const
Return a reference to the tree associated with this accessor.
Definition: ValueAccessor.h:117
ValueConverter::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:510
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
Definition: Grid.h:976
static const TreeType & constTree(GridType &g)
Definition: Grid.h:941
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:911