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;
512 template<
typename OtherValueType>
518 static Ptr create(
const ValueType& background);
523 static Ptr create(TreePtrType);
526 static Ptr create(
const GridBase& other);
532 explicit Grid(
const ValueType& background);
536 explicit Grid(TreePtrType);
544 template<
typename OtherTreeType>
564 Ptr deepCopy()
const {
return Ptr(
new Grid(*
this)); }
570 virtual Name type()
const {
return this->gridType(); }
584 const ValueType&
background()
const {
return mTree->background(); }
587 virtual bool empty()
const {
return tree().empty(); }
589 virtual void clear() { tree().clear(); }
605 ConstAccessor getAccessor()
const {
return ConstAccessor(tree()); }
609 ConstUnsafeAccessor getConstUnsafeAccessor()
const {
return ConstUnsafeAccessor(tree()); }
620 ValueOnIter beginValueOn() {
return tree().beginValueOn(); }
626 ValueOffIter beginValueOff() {
return tree().beginValueOff(); }
632 ValueAllIter beginValueAll() {
return tree().beginValueAll(); }
639 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
642 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
651 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true)
653 this->sparseFill(bbox, value, active);
666 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
669 virtual void pruneGrid(
float tolerance = 0.0);
671 #ifndef OPENVDB_2_ABI_COMPATIBLE 672 virtual void clip(
const CoordBBox&);
699 template<
typename OtherTreeType>
714 template<
typename OtherTreeType>
727 template<
typename OtherTreeType>
736 virtual CoordBBox evalActiveVoxelBoundingBox()
const;
738 virtual Coord evalActiveVoxelDim()
const;
749 TreePtrType treePtr() {
return mTree; }
752 ConstTreePtrType
treePtr()
const {
return mTree; }
757 TreeType& tree() {
return *mTree; }
762 const TreeType&
tree()
const {
return *mTree; }
775 virtual void newTree();
783 virtual void readTopology(std::istream&);
786 virtual void writeTopology(std::ostream&)
const;
789 virtual void readBuffers(std::istream&);
790 #ifndef OPENVDB_2_ABI_COMPATIBLE 791 virtual void readBuffers(std::istream&,
const CoordBBox&);
798 virtual void readNonresidentBuffers()
const;
800 virtual void writeBuffers(std::ostream&)
const;
804 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const;
839 template<
typename Gr
idType>
840 inline typename GridType::Ptr
843 return GridBase::grid<GridType>(grid);
855 template<
typename Gr
idType>
856 inline typename GridType::ConstPtr
859 return GridBase::constGrid<GridType>(grid);
872 template<
typename Gr
idType>
873 inline typename GridType::Ptr
876 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
877 return gridPtrCast<GridType>(grid->deepCopyGrid());
881 template<
typename Gr
idType>
882 inline typename GridType::Ptr
885 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
895 template<
typename _TreeType>
915 static TreeType&
tree(TreeType& t) {
return t; }
916 static TreeType&
tree(GridType& g) {
return g.
tree(); }
917 static const TreeType&
tree(
const TreeType& t) {
return t; }
918 static const TreeType&
tree(
const GridType& g) {
return g.
tree(); }
919 static const TreeType&
constTree(TreeType& t) {
return t; }
921 static const TreeType&
constTree(
const TreeType& t) {
return t; }
927 template<
typename _TreeType>
945 static TreeType&
tree(TreeType& t) {
return t; }
946 static TreeType&
tree(GridType& g) {
return g.
tree(); }
947 static const TreeType&
tree(
const TreeType& t) {
return t; }
948 static const TreeType&
tree(
const GridType& g) {
return g.
tree(); }
949 static const TreeType&
constTree(TreeType& t) {
return t; }
951 static const TreeType&
constTree(
const TreeType& t) {
return t; }
956 template<
typename _TreeType>
974 static TreeType&
tree(TreeType& t) {
return t; }
975 static TreeType&
tree(GridType& g) {
return g.
tree(); }
976 static TreeType&
tree(AccessorType& a) {
return a.
tree(); }
977 static const TreeType&
tree(
const TreeType& t) {
return t; }
978 static const TreeType&
tree(
const GridType& g) {
return g.
tree(); }
979 static const TreeType&
tree(
const AccessorType& a) {
return a.
tree(); }
980 static const TreeType&
constTree(TreeType& t) {
return t; }
982 static const TreeType&
constTree(
const TreeType& t) {
return t; }
992 template<
typename Gr
idType>
998 if (grid && grid->type() == GridType::gridType()) {
999 return boost::static_pointer_cast<GridType>(grid);
1001 return typename GridType::Ptr();
1005 template<
typename Gr
idType>
1006 inline typename GridType::ConstPtr
1009 return boost::const_pointer_cast<
const GridType>(
1010 GridBase::grid<GridType>(boost::const_pointer_cast<
GridBase>(grid)));
1014 template<
typename Gr
idType>
1015 inline typename GridType::ConstPtr
1018 return boost::const_pointer_cast<
const GridType>(GridBase::grid<GridType>(grid));
1022 template<
typename Gr
idType>
1023 inline typename GridType::ConstPtr
1026 return boost::const_pointer_cast<
const GridType>(
1027 GridBase::grid<GridType>(boost::const_pointer_cast<
GridBase>(grid)));
1034 return boost::const_pointer_cast<TreeBase>(this->constBaseTreePtr());
1049 template<
typename TreeT>
1055 template<
typename TreeT>
1061 template<
typename TreeT>
1068 template<
typename TreeT>
1071 mTree(boost::static_pointer_cast<
TreeType>(other.mTree->
copy()))
1076 template<
typename TreeT>
1077 template<
typename OtherTreeType>
1085 template<
typename TreeT>
1093 template<
typename TreeT>
1102 template<
typename TreeT>
1111 template<
typename TreeT>
1115 return Ptr(
new Grid(background));
1120 template<
typename TreeT>
1129 template<
typename TreeT>
1140 template<
typename TreeT>
1145 switch (treePolicy) {
1151 ret.reset(
new Grid(*
this));
1161 template<
typename TreeT>
1165 return this->
copy(treePolicy);
1172 template<
typename TreeT>
1177 if (tree->type() != TreeType::treeType()) {
1179 + tree->type() +
" to a grid of type " + this->
type());
1185 template<
typename TreeT>
1196 template<
typename TreeT>
1200 tree().sparseFill(bbox, value, active);
1203 template<
typename TreeT>
1207 tree().denseFill(bbox, value, active);
1210 template<
typename TreeT>
1214 this->
tree().prune(
ValueType(zeroVal<ValueType>() + tolerance));
1217 #ifndef OPENVDB_2_ABI_COMPATIBLE 1218 template<
typename TreeT>
1227 template<
typename TreeT>
1231 tree().merge(other.
tree(), policy);
1235 template<
typename TreeT>
1236 template<
typename OtherTreeType>
1240 tree().topologyUnion(other.
tree());
1244 template<
typename TreeT>
1245 template<
typename OtherTreeType>
1249 tree().topologyIntersection(other.
tree());
1253 template<
typename TreeT>
1254 template<
typename OtherTreeType>
1258 tree().topologyDifference(other.
tree());
1265 template<
typename TreeT>
1269 tree().evalMinMax(minVal, maxVal);
1273 template<
typename TreeT>
1278 tree().evalActiveVoxelBoundingBox(bbox);
1283 template<
typename TreeT>
1288 const bool nonempty =
tree().evalActiveVoxelDim(dim);
1289 return (nonempty ? dim : Coord());
1299 template<
typename TreeT>
1307 template<
typename TreeT>
1315 template<
typename TreeT>
1323 #ifndef OPENVDB_2_ABI_COMPATIBLE 1325 template<
typename TreeT>
1333 template<
typename TreeT>
1337 tree().readNonresidentBuffers();
1340 #endif // !OPENVDB_2_ABI_COMPATIBLE 1343 template<
typename TreeT>
1351 template<
typename TreeT>
1355 tree().print(os, verboseLevel);
1358 os <<
"Additional metadata:" << std::endl;
1360 os <<
" " << it->first;
1362 const std::string value = it->second->str();
1363 if (!value.empty()) os <<
": " << value;
1369 os <<
"Transform:" << std::endl;
1378 template<
typename Gr
idType>
1379 inline typename GridType::Ptr
1382 return GridType::create(background);
1386 template<
typename Gr
idType>
1387 inline typename GridType::Ptr
1390 return GridType::create();
1394 template<
typename TreePtrType>
1398 typedef typename TreePtrType::element_type
TreeType;
1403 template<
typename Gr
idType>
1404 typename GridType::Ptr
1407 typedef typename GridType::ValueType
ValueType;
1410 BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
1412 typename GridType::Ptr
grid = GridType::create(
1413 static_cast<ValueType>(voxelSize * halfWidth));
1422 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:813
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
boost::shared_ptr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:438
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:939
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:426
Base class for typed trees.
Definition: Tree.h:65
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:970
static const TreeType & tree(const GridType &g)
Definition: Grid.h:948
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:634
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:594
virtual void clear()
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:589
Grid< typename TreeType::template ValueConverter< OtherValueType >::Type > Type
Definition: Grid.h:514
static const char *const META_GRID_NAME
Definition: Grid.h:281
TreeType::Ptr TreePtrType
Definition: Grid.h:902
virtual bool empty() const
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:587
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:445
GridClass
Definition: Types.h:211
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:1301
static TreeType & tree(GridType &g)
Definition: Grid.h:975
TreeType::ValueType ValueType
Definition: Grid.h:940
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:911
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:629
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
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:1163
tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:941
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:352
static const TreeType & constTree(GridType &g)
Definition: Grid.h:981
virtual Index64 memUsage() const
Definition: Grid.h:742
Abstract base class for typed grids.
Definition: Grid.h:103
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:949
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:420
_TreeType TreeType
Definition: Grid.h:488
_TreeType::BuildType BuildType
Definition: Grid.h:492
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:901
virtual Name type() const
Return the name of this grid's type.
Definition: Grid.h:570
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:933
UnsafeAccessor 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:603
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:1247
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:1309
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:425
boost::shared_ptr< const TreeBase > ConstPtr
Definition: Tree.h:69
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:841
GridType::Ptr GridPtrType
Definition: Grid.h:907
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const
Output a human-readable description of this grid.
Definition: Grid.h:1353
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
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...
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:432
VecType
Definition: Types.h:241
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:963
TreeType::ValueType ValueType
Definition: Grid.h:969
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:912
Grid< TreeType > GridType
Definition: Grid.h:964
std::string Name
Definition: Name.h:44
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:584
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:219
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:762
tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:501
static TreeType & tree(GridType &g)
Definition: Grid.h:946
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:934
TreeType::Ptr TreePtrType
Definition: Grid.h:961
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
GridType::Ptr GridPtrType
Definition: Grid.h:937
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:968
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:1256
_TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:496
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:965
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:942
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:431
_TreeType::Ptr TreePtrType
Definition: Grid.h:489
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:931
boost::shared_ptr< TreeBase > Ptr
Definition: Tree.h:68
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1267
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:753
_TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:497
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:513
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:754
GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:909
Name name
Definition: Grid.h:446
boost::shared_ptr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:423
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1229
static TreeType & tree(TreeType &t)
Definition: Grid.h:945
Grid< TreeType > GridType
Definition: Grid.h:905
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:388
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:917
boost::shared_ptr< Grid > Ptr
Definition: Grid.h:485
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:983
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:1335
boost::shared_ptr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:433
Definition: ValueAccessor.h:219
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:952
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:335
tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:504
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:288
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:761
double Real
Definition: Types.h:64
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:398
virtual void setTree(TreeBase::Ptr)
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1174
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:921
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:286
void denseFill(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:1205
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:752
_TreeType TreeType
Definition: Grid.h:959
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1050
_TreeType TreeType
Definition: Grid.h:930
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:936
_TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:494
uint64_t Index64
Definition: Types.h:57
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:1032
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:356
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:607
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1104
#define OPENVDB_VERSION_NAME
Definition: version.h:43
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:943
virtual Index64 activeVoxelCount() const
Return the number of active voxels.
Definition: Grid.h:734
Vec3< double > Vec3d
Definition: Vec3.h:651
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:437
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:635
static TreeType & tree(GridType &g)
Definition: Grid.h:916
_TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:495
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
Definition: Grid.h:337
virtual Coord evalActiveVoxelDim() const
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1285
tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:503
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:898
TreeType::Ptr TreePtrType
Definition: Grid.h:932
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:982
CopyPolicy
Definition: Types.h:434
MergePolicy
Definition: Types.h:264
static const TreeType & constTree(GridType &g)
Definition: Grid.h:950
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
Definition: Exceptions.h:39
virtual void writeBuffers(std::ostream &) const
Write out all data buffers for this grid.
Definition: Grid.h:1345
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:938
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:922
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:947
static const char *const META_GRID_CREATOR
Definition: Grid.h:280
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:857
_TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:498
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1396
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:430
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:815
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:175
virtual Name valueType() const
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:579
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:145
virtual GridBase::Ptr deepCopyGrid() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:566
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< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:972
void sparseFill(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:1198
boost::shared_ptr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:428
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:903
_TreeType::ValueType ValueType
Definition: Grid.h:491
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
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:422
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:435
NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:904
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:979
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 const TreeType & tree(const TreeType &t)
Definition: Grid.h:977
Definition: Exceptions.h:87
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:421
_TreeType TreeType
Definition: Grid.h:900
static TreeType & tree(TreeType &t)
Definition: Grid.h:974
_TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:499
TreeType::ValueType ValueType
Definition: Grid.h:910
static const TreeType & tree(const GridType &g)
Definition: Grid.h:918
Grid< NonConstTreeType > NonConstGridType
Definition: Grid.h:906
tree::TreeBase TreeBase
Definition: Grid.h:52
tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:971
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:390
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:327
boost::shared_ptr< const Grid > ConstPtr
Definition: Grid.h:486
virtual void pruneGrid(float tolerance=0.0)
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1212
static TreeType & tree(TreeType &t)
Definition: Grid.h:915
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:1238
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:285
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:1142
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:623
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:763
GridBase(const GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:404
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:289
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:347
static const TreeType & constTree(GridType &g)
Definition: Grid.h:920
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:287
_TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:490
static const char *const META_GRID_CLASS
Definition: Grid.h:279
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:980
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:442
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:572
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:622
Definition: Exceptions.h:88
virtual void clip(const CoordBBox &)
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1220
virtual void newTree()
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1187
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:502
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:1405
virtual void readBuffers(std::istream &)
Read all data buffers for this grid.
Definition: Grid.h:1317
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:427
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:401
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:174
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:883
Grid< TreeType > GridType
Definition: Grid.h:935
TreeType & tree() const
Return a reference to the tree associated with this accessor.
Definition: ValueAccessor.h:147
static const char *const META_VECTOR_TYPE
Definition: Grid.h:284
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:436
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
boost::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:960
virtual ~Grid()
Definition: Grid.h:552
static const TreeType & tree(const GridType &g)
Definition: Grid.h:978
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:1016
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:919
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
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:651
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
Definition: Grid.h:1039
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:908
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:628
virtual ~GridBase()
Definition: Grid.h:112
GridNamePred(const Name &_name)
Definition: Grid.h:444
virtual CoordBBox evalActiveVoxelBoundingBox() const
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1275
GridType::Ptr GridPtrType
Definition: Grid.h:966
NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:967
TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:962
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:811
tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:913
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:994
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:951
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:282
static TreeType & tree(AccessorType &a)
Definition: Grid.h:976