OpenVDB 14.0.0
Loading...
Searching...
No Matches
Grid.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef OPENVDB_GRID_HAS_BEEN_INCLUDED
5#define OPENVDB_GRID_HAS_BEEN_INCLUDED
6
7#include "Exceptions.h"
8#include "MetaMap.h"
9#include "Types.h"
10#include "io/io.h"
11#include "math/Transform.h"
12#include "tree/LeafManager.h"
13#include "tree/Tree.h"
14#include "util/Assert.h"
15#include "util/logging.h"
16#include "util/Name.h"
17#include <iostream>
18#include <set>
19#include <type_traits>
20#include <vector>
21
22
23namespace openvdb {
25namespace OPENVDB_VERSION_NAME {
26
28
29template<typename> class Grid; // forward declaration
30
31
32/// @brief Create a new grid of type @c GridType with a given background value.
33///
34/// @note Calling createGrid<GridType>(background) is equivalent to calling
35/// GridType::create(background).
36template<typename GridType>
37inline typename GridType::Ptr createGrid(const typename GridType::ValueType& background);
38
39
40/// @brief Create a new grid of type @c GridType with background value zero.
41///
42/// @note Calling createGrid<GridType>() is equivalent to calling GridType::create().
43template<typename GridType>
44inline typename GridType::Ptr createGrid();
45
46
47/// @brief Create a new grid of the appropriate type that wraps the given tree.
48///
49/// @note This function can be called without specifying the template argument,
50/// i.e., as createGrid(tree).
51template<typename TreePtrType>
53
54
55/// @brief Create a new grid of type @c GridType classified as a "Level Set",
56/// i.e., a narrow-band level set.
57///
58/// @note @c GridType::ValueType must be a floating-point scalar.
59///
60/// @param voxelSize the size of a voxel in world units
61/// @param halfWidth the half width of the narrow band in voxel units
62///
63/// @details The voxel size and the narrow band half width define the grid's
64/// background value as halfWidth*voxelWidth. The transform is linear
65/// with a uniform scaling only corresponding to the specified voxel size.
66///
67/// @note It is generally advisable to specify a half-width of the narrow band
68/// that is larger than one voxel unit, otherwise zero crossings are not guaranteed.
69template<typename GridType>
70typename GridType::Ptr createLevelSet(
71 Real voxelSize = 1.0, Real halfWidth = LEVEL_SET_HALF_WIDTH);
72
73
74////////////////////////////////////////
75
76
77/// @brief Abstract base class for typed grids
79{
80public:
83
84 using GridFactory = Ptr (*)();
85
86
87 ~GridBase() override {}
88
89
90 /// @name Copying
91 /// @{
92
93 /// @brief Return a new grid of the same type as this grid whose metadata is a
94 /// deep copy of this grid's and whose tree and transform are shared with this grid.
95 virtual GridBase::Ptr copyGrid() = 0;
96 /// @brief Return a new grid of the same type as this grid whose metadata is a
97 /// deep copy of this grid's and whose tree and transform are shared with this grid.
98 virtual GridBase::ConstPtr copyGrid() const = 0;
99 /// @brief Return a new grid of the same type as this grid whose metadata and
100 /// transform are deep copies of this grid's and whose tree is default-constructed.
102
103 /// @brief Return a new grid of the same type as this grid whose tree and transform
104 /// is shared with this grid and whose metadata is provided as an argument.
106 /// @brief Return a new grid of the same type as this grid whose tree is shared with
107 /// this grid, whose metadata is a deep copy of this grid's and whose transform is
108 /// provided as an argument.
109 /// @throw ValueError if the transform pointer is null
111 /// @brief Return a new grid of the same type as this grid whose tree is shared with
112 /// this grid and whose transform and metadata are provided as arguments.
113 /// @throw ValueError if the transform pointer is null
115 math::Transform::Ptr xform) const = 0;
116
117 /// Return a new grid whose metadata, transform and tree are deep copies of this grid's.
118 virtual GridBase::Ptr deepCopyGrid() const = 0;
119
120 /// @}
121
122
123 /// @name Registry
124 /// @{
125
126 /// Create a new grid of the given (registered) type.
127 static Ptr createGrid(const Name& type);
128
129 /// Return @c true if the given grid type name is registered.
130 static bool isRegistered(const Name &type);
131
132 /// Clear the grid type registry.
133 static void clearRegistry();
134
135 /// @}
136
137 /// @name Type access
138 /// @{
139
140 /// Return the name of this grid's type.
141 virtual Name type() const = 0;
142 /// Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
143 virtual Name valueType() const = 0;
144
145 /// Return @c true if this grid is of the same type as the template parameter.
146 template<typename GridType>
147 bool isType() const { return (this->type() == GridType::gridType()); }
148
149 /// @}
150
151 //@{
152 /// @brief Return the result of downcasting a GridBase pointer to a Grid pointer
153 /// of the specified type, or return a null pointer if the types are incompatible.
154 template<typename GridType>
155 static typename GridType::Ptr grid(const GridBase::Ptr&);
156 template<typename GridType>
157 static typename GridType::ConstPtr grid(const GridBase::ConstPtr&);
158 template<typename GridType>
159 static typename GridType::ConstPtr constGrid(const GridBase::Ptr&);
160 template<typename GridType>
161 static typename GridType::ConstPtr constGrid(const GridBase::ConstPtr&);
162 //@}
163
164 /// @name Tree
165 /// @{
166
167 /// @brief Return a pointer to this grid's tree, which might be
168 /// shared with other grids. The pointer is guaranteed to be non-null.
170 /// @brief Return a pointer to this grid's tree, which might be
171 /// shared with other grids. The pointer is guaranteed to be non-null.
173 /// @brief Return a pointer to this grid's tree, which might be
174 /// shared with other grids. The pointer is guaranteed to be non-null.
176
177 /// @brief Return true if tree is not shared with another grid.
178 virtual bool isTreeUnique() const = 0;
179
180 /// @brief Return a reference to this grid's tree, which might be
181 /// shared with other grids.
182 /// @note Calling @vdblink::GridBase::setTree() setTree@endlink
183 /// on this grid invalidates all references previously returned by this method.
184 TreeBase& baseTree() { return const_cast<TreeBase&>(this->constBaseTree()); }
185 /// @brief Return a reference to this grid's tree, which might be
186 /// shared with other grids.
187 /// @note Calling @vdblink::GridBase::setTree() setTree@endlink
188 /// on this grid invalidates all references previously returned by this method.
189 const TreeBase& baseTree() const { return this->constBaseTree(); }
190 /// @brief Return a reference to this grid's tree, which might be
191 /// shared with other grids.
192 /// @note Calling @vdblink::GridBase::setTree() setTree@endlink
193 /// on this grid invalidates all references previously returned by this method.
194 const TreeBase& constBaseTree() const { return *(this->constBaseTreePtr()); }
195
196 /// @brief Associate the given tree with this grid, in place of its existing tree.
197 /// @throw ValueError if the tree pointer is null
198 /// @throw TypeError if the tree is not of the appropriate type
199 /// @note Invalidates all references previously returned by
200 /// @vdblink::GridBase::baseTree() baseTree@endlink
201 /// or @vdblink::GridBase::constBaseTree() constBaseTree@endlink.
202 virtual void setTree(TreeBase::Ptr) = 0;
203
204 /// Set a new tree with the same background value as the previous tree.
205 virtual void newTree() = 0;
206
207 /// @}
208
209 /// Return @c true if this grid contains only background voxels.
210 virtual bool empty() const = 0;
211 /// Empty this grid, setting all voxels to the background.
212 virtual void clear() = 0;
213
214
215 /// @name Tools
216 /// @{
217
218 /// @brief Reduce the memory footprint of this grid by increasing its sparseness
219 /// either losslessly (@a tolerance = 0) or lossily (@a tolerance > 0).
220 /// @details With @a tolerance > 0, sparsify regions where voxels have the same
221 /// active state and have values that differ by no more than the tolerance
222 /// (converted to this grid's value type).
223 virtual void pruneGrid(float tolerance = 0.0) = 0;
224
225 /// @brief Clip this grid to the given world-space bounding box.
226 /// @details Voxels that lie outside the bounding box are set to the background.
227 /// @warning Clipping a level set will likely produce a grid that is
228 /// no longer a valid level set.
229 void clipGrid(const BBoxd&);
230
231 /// @brief Clip this grid to the given index-space bounding box.
232 /// @details Voxels that lie outside the bounding box are set to the background.
233 /// @warning Clipping a level set will likely produce a grid that is
234 /// no longer a valid level set.
235 virtual void clip(const CoordBBox&) = 0;
236
237 /// @}
238
239 /// @{
240 /// @brief If this grid resolves to one of the listed grid types,
241 /// invoke the given functor on the resolved grid.
242 /// @return @c false if this grid's type is not one of the listed types
243 ///
244 /// @par Example:
245 /// @code
246 /// using AllowedGridTypes = openvdb::TypeList<
247 /// openvdb::Int32Grid, openvdb::Int64Grid,
248 /// openvdb::FloatGrid, openvdb::DoubleGrid>;
249 ///
250 /// const openvdb::CoordBBox bbox{
251 /// openvdb::Coord{0,0,0}, openvdb::Coord{10,10,10}};
252 ///
253 /// // Fill the grid if it is one of the allowed types.
254 /// myGridBasePtr->apply<AllowedGridTypes>(
255 /// [&bbox](auto& grid) { // C++14
256 /// using GridType = typename std::decay<decltype(grid)>::type;
257 /// grid.fill(bbox, typename GridType::ValueType(1));
258 /// }
259 /// );
260 /// @endcode
261 ///
262 /// @see @vdblink::TypeList TypeList@endlink
263 template<typename GridTypeListT, typename OpT> inline bool apply(OpT&) const;
264 template<typename GridTypeListT, typename OpT> inline bool apply(OpT&);
265 template<typename GridTypeListT, typename OpT> inline bool apply(const OpT&) const;
266 template<typename GridTypeListT, typename OpT> inline bool apply(const OpT&);
267 /// @}
268
269 /// @name Metadata
270 /// @{
271
272 /// Return this grid's user-specified name.
273 std::string getName() const;
274 /// Specify a name for this grid.
275 void setName(const std::string&);
276
277 /// Return the user-specified description of this grid's creator.
278 std::string getCreator() const;
279 /// Provide a description of this grid's creator.
280 void setCreator(const std::string&);
281
282 /// @brief Return @c true if this grid should be written out with floating-point
283 /// voxel values (including components of vectors) quantized to 16 bits.
284 bool saveFloatAsHalf() const;
286
287 /// @brief Return the class of volumetric data (level set, fog volume, etc.)
288 /// that is stored in this grid.
289 /// @sa gridClassToString, gridClassToMenuName, stringToGridClass
291 /// @brief Specify the class of volumetric data (level set, fog volume, etc.)
292 /// that is stored in this grid.
293 /// @sa gridClassToString, gridClassToMenuName, stringToGridClass
295 /// Remove the setting specifying the class of this grid's volumetric data.
297
298 /// @}
299
300 /// Return the metadata string value for the given class of volumetric data.
301 static std::string gridClassToString(GridClass);
302 /// Return a formatted string version of the grid class.
303 static std::string gridClassToMenuName(GridClass);
304 /// @brief Return the class of volumetric data specified by the given string.
305 /// @details If the string is not one of the ones returned by
306 /// @vdblink::GridBase::gridClassToString() gridClassToString@endlink,
307 /// return @c GRID_UNKNOWN.
308 static GridClass stringToGridClass(const std::string&);
309
310 /// @name Metadata
311 /// @{
312
313 /// @brief Return the type of vector data (invariant, covariant, etc.) stored
314 /// in this grid, assuming that this grid contains a vector-valued tree.
315 /// @sa vecTypeToString, vecTypeExamples, vecTypeDescription, stringToVecType
317 /// @brief Specify the type of vector data (invariant, covariant, etc.) stored
318 /// in this grid, assuming that this grid contains a vector-valued tree.
319 /// @sa vecTypeToString, vecTypeExamples, vecTypeDescription, stringToVecType
321 /// Remove the setting specifying the type of vector data stored in this grid.
323
324 /// @}
325
326 /// Return the metadata string value for the given type of vector data.
327 static std::string vecTypeToString(VecType);
328 /// Return a string listing examples of the given type of vector data
329 /// (e.g., "Gradient/Normal", given VEC_COVARIANT).
330 static std::string vecTypeExamples(VecType);
331 /// @brief Return a string describing how the given type of vector data is affected
332 /// by transformations (e.g., "Does not transform", given VEC_INVARIANT).
333 static std::string vecTypeDescription(VecType);
334 static VecType stringToVecType(const std::string&);
335
336 /// @name Metadata
337 /// @{
338
339 /// Return @c true if this grid's voxel values are in world space and should be
340 /// affected by transformations, @c false if they are in local space and should
341 /// not be affected by transformations.
342 bool isInWorldSpace() const;
343 /// Specify whether this grid's voxel values are in world space or in local space.
345
346 /// @}
347
348 // Standard metadata field names
349 // (These fields should normally not be accessed directly, but rather
350 // via the accessor methods above, when available.)
351 // Note: Visual C++ requires these declarations to be separate statements.
352 static const char* const META_GRID_CLASS;
353 static const char* const META_GRID_CREATOR;
354 static const char* const META_GRID_NAME;
355 static const char* const META_SAVE_HALF_FLOAT;
356 static const char* const META_IS_LOCAL_SPACE;
357 static const char* const META_VECTOR_TYPE;
358 static const char* const META_FILE_BBOX_MIN;
359 static const char* const META_FILE_BBOX_MAX;
360 static const char* const META_FILE_COMPRESSION;
361 static const char* const META_FILE_MEM_BYTES;
362 static const char* const META_FILE_VOXEL_COUNT;
363 static const char* const META_FILE_DELAYED_LOAD;
364
365
366 /// @name Statistics
367 /// @{
368
369 /// Return the number of active voxels.
370 virtual Index64 activeVoxelCount() const = 0;
371
372 /// Return the axis-aligned bounding box of all active voxels. If
373 /// the grid is empty a default bbox is returned.
375
376 /// Return the dimensions of the axis-aligned bounding box of all active voxels.
377 virtual Coord evalActiveVoxelDim() const = 0;
378
379 /// Return the number of bytes of memory used by this grid.
380 virtual Index64 memUsage() const = 0;
381
382 /// @brief Add metadata to this grid comprising the current values
383 /// of statistics like the active voxel count and bounding box.
384 /// @note This metadata is not automatically kept up-to-date with
385 /// changes to this grid.
387 /// @brief Return a new MetaMap containing just the metadata that
388 /// was added to this grid with @vdblink::GridBase::addStatsMetadata()
389 /// addStatsMetadata@endlink.
390 /// @details If @vdblink::GridBase::addStatsMetadata() addStatsMetadata@endlink
391 /// was never called on this grid, return an empty MetaMap.
393
394 /// @}
395
396
397 /// @name Transform
398 /// @{
399
400 //@{
401 /// @brief Return a pointer to this grid's transform, which might be
402 /// shared with other grids.
403 math::Transform::Ptr transformPtr() { return mTransform; }
404 math::Transform::ConstPtr transformPtr() const { return mTransform; }
405 math::Transform::ConstPtr constTransformPtr() const { return mTransform; }
406 //@}
407 //@{
408 /// @brief Return a reference to this grid's transform, which might be
409 /// shared with other grids.
410 /// @note Calling @vdblink::GridBase::setTransform() setTransform@endlink
411 /// on this grid invalidates all references previously returned by this method.
412 math::Transform& transform() { return *mTransform; }
413 const math::Transform& transform() const { return *mTransform; }
414 const math::Transform& constTransform() const { return *mTransform; }
415 //@}
416
417 /// @}
418
419 /// @name Transform
420 /// @{
421
422 /// @brief Associate the given transform with this grid, in place of
423 /// its existing transform.
424 /// @throw ValueError if the transform pointer is null
425 /// @note Invalidates all references previously returned by
426 /// @vdblink::GridBase::transform() transform@endlink
427 /// or @vdblink::GridBase::constTransform() constTransform@endlink.
429
430 /// Return the size of this grid's voxels.
431 Vec3d voxelSize() const { return transform().voxelSize(); }
432 /// @brief Return the size of this grid's voxel at position (x, y, z).
433 /// @note Frustum and perspective transforms have position-dependent voxel size.
434 Vec3d voxelSize(const Vec3d& xyz) const { return transform().voxelSize(xyz); }
435 /// Return true if the voxels in world space are uniformly sized cubes
436 bool hasUniformVoxels() const { return mTransform->hasUniformScale(); }
437 /// Apply this grid's transform to the given coordinates.
438 Vec3d indexToWorld(const Vec3d& xyz) const { return transform().indexToWorld(xyz); }
439 /// Apply this grid's transform to the given coordinates.
440 Vec3d indexToWorld(const Coord& ijk) const { return transform().indexToWorld(ijk); }
441 /// Apply the inverse of this grid's transform to the given coordinates.
442 Vec3d worldToIndex(const Vec3d& xyz) const { return transform().worldToIndex(xyz); }
443
444 /// @}
445
446 /// @name I/O
447 /// @{
448
449#if OPENVDB_ABI_VERSION_NUMBER < 14
450 /// @brief Read the grid topology from a stream.
451 /// This will read only the grid structure, not the actual data buffers.
452 virtual void readTopology(std::istream&) = 0;
453 /// @brief Write the grid topology to a stream.
454 /// This will write only the grid structure, not the actual data buffers.
455 virtual void writeTopology(std::ostream&) const = 0;
456
457 /// Read all data buffers for this grid.
458 virtual void readBuffers(std::istream&) = 0;
459 /// Read all of this grid's data buffers that intersect the given index-space bounding box.
460 virtual void readBuffers(std::istream&, const CoordBBox&) = 0;
461
462 OPENVDB_DEPRECATED_MESSAGE("This method is deprecated and will be removed. Delayed loading is no longer supported.")
463 virtual void readNonresidentBuffers() const = 0;
464
465 /// Write out all data buffers for this grid.
466 virtual void writeBuffers(std::ostream&) const = 0;
467#endif
468
469 /// Read in the transform for this grid.
470 void readTransform(std::istream& is) { transform().read(is); }
471 /// Write out the transform for this grid.
472 void writeTransform(std::ostream& os) const { transform().write(os); }
473
474 /// Output a human-readable description of this grid.
475 virtual void print(std::ostream& = std::cout, int verboseLevel = 1) const = 0;
476
477 /// @}
478
479
480protected:
481 /// @brief Initialize with an identity linear transform.
482 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
483
484 /// @brief Initialize with metadata and a transform.
485 /// @throw ValueError if the transform pointer is null
486 GridBase(const MetaMap& meta, math::Transform::Ptr xform);
487
488 /// @brief Deep copy another grid's metadata and transform.
489 GridBase(const GridBase& other): MetaMap(other), mTransform(other.mTransform->copy()) {}
490
491 /// @brief Copy another grid's metadata but share its transform.
492 GridBase(GridBase& other, ShallowCopy): MetaMap(other), mTransform(other.mTransform) {}
493
494 /// Register a grid type along with a factory function.
495 static void registerGrid(const Name& type, GridFactory);
496 /// Remove a grid type from the registry.
497 static void unregisterGrid(const Name& type);
498
499
500private:
501 math::Transform::Ptr mTransform;
502}; // class GridBase
503
504
505////////////////////////////////////////
506
507
508using GridPtrVec = std::vector<GridBase::Ptr>;
509using GridPtrVecIter = GridPtrVec::iterator;
510using GridPtrVecCIter = GridPtrVec::const_iterator;
512
513using GridCPtrVec = std::vector<GridBase::ConstPtr>;
514using GridCPtrVecIter = GridCPtrVec::iterator;
515using GridCPtrVecCIter = GridCPtrVec::const_iterator;
517
518using GridPtrSet = std::set<GridBase::Ptr>;
519using GridPtrSetIter = GridPtrSet::iterator;
520using GridPtrSetCIter = GridPtrSet::const_iterator;
522
523using GridCPtrSet = std::set<GridBase::ConstPtr>;
524using GridCPtrSetIter = GridCPtrSet::iterator;
525using GridCPtrSetCIter = GridCPtrSet::const_iterator;
527
528
529/// @brief Predicate functor that returns @c true for grids that have a specified name
531{
532 GridNamePred(const Name& _name): name(_name) {}
533 bool operator()(const GridBase::ConstPtr& g) const { return g && g->getName() == name; }
535};
536
537/// Return the first grid in the given container whose name is @a name.
538template<typename GridPtrContainerT>
539inline typename GridPtrContainerT::value_type
540findGridByName(const GridPtrContainerT& container, const Name& name)
541{
542 using GridPtrT = typename GridPtrContainerT::value_type;
543 typename GridPtrContainerT::const_iterator it =
544 std::find_if(container.begin(), container.end(), GridNamePred(name));
545 return (it == container.end() ? GridPtrT() : *it);
546}
547
548/// Return the first grid in the given map whose name is @a name.
549template<typename KeyT, typename GridPtrT>
550inline GridPtrT
551findGridByName(const std::map<KeyT, GridPtrT>& container, const Name& name)
552{
553 using GridPtrMapT = std::map<KeyT, GridPtrT>;
554 for (typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
555 it != end; ++it)
556 {
557 const GridPtrT& grid = it->second;
558 if (grid && grid->getName() == name) return grid;
559 }
560 return GridPtrT();
561}
562//@}
563
564
565////////////////////////////////////////
566
567
568/// @brief Container class that associates a tree with a transform and metadata
569template<typename _TreeType>
570class Grid: public GridBase
571{
572public:
575
576 using TreeType = _TreeType;
577 using TreePtrType = typename _TreeType::Ptr;
578 using ConstTreePtrType = typename _TreeType::ConstPtr;
579 using ValueType = typename _TreeType::ValueType;
580 using BuildType = typename _TreeType::BuildType;
581
582 using ValueOnIter = typename _TreeType::ValueOnIter;
583 using ValueOnCIter = typename _TreeType::ValueOnCIter;
584 using ValueOffIter = typename _TreeType::ValueOffIter;
585 using ValueOffCIter = typename _TreeType::ValueOffCIter;
586 using ValueAllIter = typename _TreeType::ValueAllIter;
587 using ValueAllCIter = typename _TreeType::ValueAllCIter;
588
589 using Accessor = typename _TreeType::Accessor;
590 using ConstAccessor = typename _TreeType::ConstAccessor;
591 using UnsafeAccessor = typename _TreeType::UnsafeAccessor;
592 using ConstUnsafeAccessor = typename _TreeType::ConstUnsafeAccessor;
593
594 /// @brief ValueConverter<T>::Type is the type of a grid having the same
595 /// hierarchy as this grid but a different value type, T.
596 ///
597 /// For example, FloatGrid::ValueConverter<double>::Type is equivalent to DoubleGrid.
598 /// @note If the source grid type is a template argument, it might be necessary
599 /// to write "typename SourceGrid::template ValueConverter<T>::Type".
600 template<typename OtherValueType>
604
605 /// Return a new grid with the given background value.
607 /// Return a new grid with background value zero.
608 static Ptr create();
609 /// @brief Return a new grid that contains the given tree.
610 /// @throw ValueError if the tree pointer is null
612 /// @brief Return a new, empty grid with the same transform and metadata as the
613 /// given grid and with background value zero.
614 static Ptr create(const GridBase& other);
615
616
617 /// Construct a new grid with background value zero.
619 /// Construct a new grid with the given background value.
620 explicit Grid(const ValueType& background);
621 /// @brief Construct a new grid that shares the given tree and associates with it
622 /// an identity linear transform.
623 /// @throw ValueError if the tree pointer is null
624 explicit Grid(TreePtrType);
625 /// Deep copy another grid's metadata, transform and tree.
626 Grid(const Grid&);
627 /// @brief Deep copy the metadata, transform and tree of another grid whose tree
628 /// configuration is the same as this grid's but whose value type is different.
629 /// Cast the other grid's values to this grid's value type.
630 /// @throw TypeError if the other grid's tree configuration doesn't match this grid's
631 /// or if this grid's ValueType is not constructible from the other grid's ValueType.
632 template<typename OtherTreeType>
633 explicit Grid(const Grid<OtherTreeType>&);
634 /// Deep copy another grid's metadata and transform, but share its tree.
636 /// @brief Deep copy another grid's metadata and transform, but construct a new tree
637 /// with background value zero.
638 explicit Grid(const GridBase&);
639
640 ~Grid() override {}
641
642 /// Disallow assignment, since it wouldn't be obvious whether the copy is deep or shallow.
643 Grid& operator=(const Grid&) = delete;
644
645 /// @name Copying
646 /// @{
647
648 /// @brief Return a new grid of the same type as this grid whose metadata and
649 /// transform are deep copies of this grid's and whose tree is shared with this grid.
651 /// @brief Return a new grid of the same type as this grid whose metadata and
652 /// transform are deep copies of this grid's and whose tree is shared with this grid.
653 ConstPtr copy() const;
654 /// @brief Return a new grid of the same type as this grid whose metadata and
655 /// transform are deep copies of this grid's and whose tree is default-constructed.
657
658 /// @brief Return a new grid of the same type as this grid whose metadata is a
659 /// deep copy of this grid's and whose tree and transform are shared with this grid.
661 /// @brief Return a new grid of the same type as this grid whose metadata is a
662 /// deep copy of this grid's and whose tree and transform are shared with this grid.
663 GridBase::ConstPtr copyGrid() const override;
664 /// @brief Return a new grid of the same type as this grid whose metadata and
665 /// transform are deep copies of this grid's and whose tree is default-constructed.
667 //@}
668
669 /// @name Copying
670 /// @{
671
672 /// @brief Return a new grid of the same type as this grid whose tree and transform
673 /// is shared with this grid and whose metadata is provided as an argument.
675 /// @brief Return a new grid of the same type as this grid whose tree is shared with
676 /// this grid, whose metadata is a deep copy of this grid's and whose transform is
677 /// provided as an argument.
678 /// @throw ValueError if the transform pointer is null
680 /// @brief Return a new grid of the same type as this grid whose tree is shared with
681 /// this grid and whose transform and metadata are provided as arguments.
682 /// @throw ValueError if the transform pointer is null
684 math::Transform::Ptr xform) const;
685
686 /// @brief Return a new grid of the same type as this grid whose tree and transform
687 /// is shared with this grid and whose metadata is provided as an argument.
689 /// @brief Return a new grid of the same type as this grid whose tree is shared with
690 /// this grid, whose metadata is a deep copy of this grid's and whose transform is
691 /// provided as an argument.
692 /// @throw ValueError if the transform pointer is null
694 /// @brief Return a new grid of the same type as this grid whose tree is shared with
695 /// this grid and whose transform and metadata are provided as arguments.
696 /// @throw ValueError if the transform pointer is null
698 math::Transform::Ptr xform) const override;
699
700 /// @brief Return a new grid whose metadata, transform and tree are deep copies of this grid's.
701 Ptr deepCopy() const { return Ptr(new Grid(*this)); }
702 /// @brief Return a new grid whose metadata, transform and tree are deep copies of this grid's.
703 GridBase::Ptr deepCopyGrid() const override { return this->deepCopy(); }
704
705 //@}
706
707
708 /// Return the name of this grid's type.
709 Name type() const override { return this->gridType(); }
710 /// Return the name of this type of grid.
711 static Name gridType() { return TreeType::treeType(); }
712
713 /// Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
714 Name valueType() const override { return tree().valueType(); }
715
716
717 /// @name Voxel access
718 /// @{
719
720 /// @brief Return this grid's background value.
721 /// @note Use tools::changeBackground to efficiently modify the background value.
722 const ValueType& background() const { return mTree->background(); }
723
724 /// Return @c true if this grid contains only inactive background voxels.
725 bool empty() const override { return tree().empty(); }
726 /// Empty this grid, so that all voxels become inactive background voxels.
727 void clear() override { tree().clear(); }
728
729 /// @brief Return an accessor that provides random read and write access
730 /// to this grid's voxels.
731 /// @details The accessor is safe in the sense that it is registered with this grid's tree.
732 Accessor getAccessor() { return mTree->getAccessor(); }
733 /// @brief Return an unsafe accessor that provides random read and write access
734 /// to this grid's voxels.
735 /// @details The accessor is unsafe in the sense that it is not registered
736 /// with this grid's tree. In some rare cases this can give a performance advantage
737 /// over a registered accessor, but it is unsafe if the tree topology is modified.
738 /// @warning Only use this method if you're an expert and know the
739 /// risks of using an unregistered accessor (see tree/ValueAccessor.h)
740 UnsafeAccessor getUnsafeAccessor() { return mTree->getUnsafeAccessor(); }
741 /// Return an accessor that provides random read-only access to this grid's voxels.
742 ConstAccessor getAccessor() const { return mTree->getConstAccessor(); }
743 /// Return an accessor that provides random read-only access to this grid's voxels.
744 ConstAccessor getConstAccessor() const { return mTree->getConstAccessor(); }
745 /// @brief Return an unsafe accessor that provides random read-only access
746 /// to this grid's voxels.
747 /// @details The accessor is unsafe in the sense that it is not registered
748 /// with this grid's tree. In some rare cases this can give a performance advantage
749 /// over a registered accessor, but it is unsafe if the tree topology is modified.
750 /// @warning Only use this method if you're an expert and know the
751 /// risks of using an unregistered accessor (see tree/ValueAccessor.h)
752 ConstUnsafeAccessor getConstUnsafeAccessor() const { return mTree->getConstUnsafeAccessor(); }
753
754 /// Return an iterator over all of this grid's active values (tile and voxel).
755 ValueOnIter beginValueOn() { return tree().beginValueOn(); }
756 /// Return an iterator over all of this grid's active values (tile and voxel).
757 ValueOnCIter beginValueOn() const { return tree().cbeginValueOn(); }
758 /// Return an iterator over all of this grid's active values (tile and voxel).
759 ValueOnCIter cbeginValueOn() const { return tree().cbeginValueOn(); }
760 /// Return an iterator over all of this grid's inactive values (tile and voxel).
761 ValueOffIter beginValueOff() { return tree().beginValueOff(); }
762 /// Return an iterator over all of this grid's inactive values (tile and voxel).
763 ValueOffCIter beginValueOff() const { return tree().cbeginValueOff(); }
764 /// Return an iterator over all of this grid's inactive values (tile and voxel).
765 ValueOffCIter cbeginValueOff() const { return tree().cbeginValueOff(); }
766 /// Return an iterator over all of this grid's values (tile and voxel).
767 ValueAllIter beginValueAll() { return tree().beginValueAll(); }
768 /// Return an iterator over all of this grid's values (tile and voxel).
769 ValueAllCIter beginValueAll() const { return tree().cbeginValueAll(); }
770 /// Return an iterator over all of this grid's values (tile and voxel).
771 ValueAllCIter cbeginValueAll() const { return tree().cbeginValueAll(); }
772
773 /// @}
774
775 /// @name Tools
776 /// @{
777
778 /// @brief Set all voxels within a given axis-aligned box to a constant value.
779 /// @param bbox inclusive coordinates of opposite corners of an axis-aligned box
780 /// @param value the value to which to set voxels within the box
781 /// @param active if true, mark voxels within the box as active,
782 /// otherwise mark them as inactive
783 /// @note This operation generates a sparse, but not always optimally sparse,
784 /// representation of the filled box. Follow fill operations with a prune()
785 /// operation for optimal sparseness.
786 void sparseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
787
788 /// @brief Set all voxels within a given axis-aligned box to a constant value.
789 /// @param bbox inclusive coordinates of opposite corners of an axis-aligned box
790 /// @param value the value to which to set voxels within the box
791 /// @param active if true, mark voxels within the box as active,
792 /// otherwise mark them as inactive
793 /// @note This operation generates a sparse, but not always optimally sparse,
794 /// representation of the filled box. Follow fill operations with a prune()
795 /// operation for optimal sparseness.
796 /// @details Identical to sparseFill defined above.
797 void fill(const CoordBBox& bbox, const ValueType& value, bool active = true);
798
799 /// @brief Set all voxels within a given axis-aligned box to a constant value
800 /// and ensure that those voxels are all represented at the leaf level.
801 /// @param bbox inclusive coordinates of opposite corners of an axis-aligned box.
802 /// @param value the value to which to set voxels within the box.
803 /// @param active if true, mark voxels within the box as active,
804 /// otherwise mark them as inactive.
805 void denseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
806
807 /// Reduce the memory footprint of this grid by increasing its sparseness.
808 void pruneGrid(float tolerance = 0.0) override;
809
810 /// @brief Clip this grid to the given index-space bounding box.
811 /// @details Voxels that lie outside the bounding box are set to the background.
812 /// @warning Clipping a level set will likely produce a grid that is
813 /// no longer a valid level set.
814 void clip(const CoordBBox&) override;
815
816 /// @brief Efficiently merge another grid into this grid using one of several schemes.
817 /// @details This operation is primarily intended to combine grids that are mostly
818 /// non-overlapping (for example, intermediate grids from computations that are
819 /// parallelized across disjoint regions of space).
820 /// @warning This operation always empties the other grid.
822
823 /// @brief Union this grid's set of active values with the active values
824 /// of the other grid, whose value type may be different.
825 /// @details The resulting state of a value is active if the corresponding value
826 /// was already active OR if it is active in the other grid. Also, a resulting
827 /// value maps to a voxel if the corresponding value already mapped to a voxel
828 /// OR if it is a voxel in the other grid. Thus, a resulting value can only
829 /// map to a tile if the corresponding value already mapped to a tile
830 /// AND if it is a tile value in the other grid.
831 ///
832 /// @note This operation modifies only active states, not values.
833 /// Specifically, active tiles and voxels in this grid are not changed, and
834 /// tiles or voxels that were inactive in this grid but active in the other grid
835 /// are marked as active in this grid but left with their original values.
836 template<typename OtherTreeType>
838
839 /// @brief Intersect this grid's set of active values with the active values
840 /// of the other grid, whose value type may be different.
841 /// @details The resulting state of a value is active only if the corresponding
842 /// value was already active AND if it is active in the other tree. Also, a
843 /// resulting value maps to a voxel if the corresponding value
844 /// already mapped to an active voxel in either of the two grids
845 /// and it maps to an active tile or voxel in the other grid.
846 ///
847 /// @note This operation can delete branches of this grid that overlap with
848 /// inactive tiles in the other grid. Also, because it can deactivate voxels,
849 /// it can create leaf nodes with no active values. Thus, it is recommended
850 /// to prune this grid after calling this method.
851 template<typename OtherTreeType>
853
854 /// @brief Difference this grid's set of active values with the active values
855 /// of the other grid, whose value type may be different.
856 /// @details After this method is called, voxels in this grid will be active
857 /// only if they were active to begin with and if the corresponding voxels
858 /// in the other grid were inactive.
859 ///
860 /// @note This operation can delete branches of this grid that overlap with
861 /// active tiles in the other grid. Also, because it can deactivate voxels,
862 /// it can create leaf nodes with no active values. Thus, it is recommended
863 /// to prune this grid after calling this method.
864 template<typename OtherTreeType>
866
867 /// @}
868
869 /// @name Statistics
870 /// @{
871
872 /// Return the number of active voxels.
873 Index64 activeVoxelCount() const override { return tree().activeVoxelCount(); }
874 /// Return the axis-aligned bounding box of all active voxels.
876 /// Return the dimensions of the axis-aligned bounding box of all active voxels.
877 Coord evalActiveVoxelDim() const override;
878
879 /// Return the number of bytes of memory used by this grid.
880 /// @todo Add transform().memUsage()
881 Index64 memUsage() const override { return tree().memUsage(); }
882
883 /// @}
884
885
886 /// @name Tree
887 /// @{
888
889 //@{
890 /// @brief Return a pointer to this grid's tree, which might be
891 /// shared with other grids. The pointer is guaranteed to be non-null.
892 TreePtrType treePtr() { return mTree; }
893 ConstTreePtrType treePtr() const { return mTree; }
894 ConstTreePtrType constTreePtr() const { return mTree; }
895 TreeBase::ConstPtr constBaseTreePtr() const override { return mTree; }
896 //@}
897 /// @brief Return true if tree is not shared with another grid.
898 /// @note This is a virtual function with ABI=8
899 bool isTreeUnique() const final;
900
901 //@{
902 /// @brief Return a reference to this grid's tree, which might be
903 /// shared with other grids.
904 /// @note Calling setTree() on this grid invalidates all references
905 /// previously returned by this method.
906 TreeType& tree() { return *mTree; }
907 const TreeType& tree() const { return *mTree; }
908 const TreeType& constTree() const { return *mTree; }
909 //@}
910
911 /// @}
912
913 /// @name Tree
914 /// @{
915
916 /// @brief Associate the given tree with this grid, in place of its existing tree.
917 /// @throw ValueError if the tree pointer is null
918 /// @throw TypeError if the tree is not of type TreeType
919 /// @note Invalidates all references previously returned by baseTree(),
920 /// constBaseTree(), tree() or constTree().
921 void setTree(TreeBase::Ptr) override;
922
923 /// @brief Associate a new, empty tree with this grid, in place of its existing tree.
924 /// @note The new tree has the same background value as the existing tree.
925 void newTree() override;
926
927 /// @}
928
929
930 /// @name I/O
931 /// @{
932
933#if OPENVDB_ABI_VERSION_NUMBER < 14
934 /// @brief Read the grid topology from a stream.
935 /// This will read only the grid structure, not the actual data buffers.
936 void readTopology(std::istream&) override;
937 /// @brief Write the grid topology to a stream.
938 /// This will write only the grid structure, not the actual data buffers.
939 void writeTopology(std::ostream&) const override;
940
941 /// Read all data buffers for this grid.
942 void readBuffers(std::istream&) override;
943 /// Read all of this grid's data buffers that intersect the given index-space bounding box.
944 void readBuffers(std::istream&, const CoordBBox&) override;
945
946 OPENVDB_DEPRECATED_MESSAGE("This method is deprecated and will be removed. Delayed loading is no longer supported.")
947 void readNonresidentBuffers() const override { }
948
949 /// Write out all data buffers for this grid.
950 void writeBuffers(std::ostream&) const override;
951
952#endif // OPENVDB_ABI_VERSION_NUMBER < 14
953
954 /// Output a human-readable description of this grid.
955 void print(std::ostream& = std::cout, int verboseLevel = 1) const override;
956
957 /// @}
958
959 /// @brief Return @c true if grids of this type require multiple I/O passes
960 /// to read and write data buffers.
961 /// @sa HasMultiPassIO
962 static inline bool hasMultiPassIO();
963
964
965 /// @name Registry
966 /// @{
967
968 /// Return @c true if this grid type is registered.
970 /// Register this grid type along with a factory function.
971 static void registerGrid() { GridBase::registerGrid(Grid::gridType(), Grid::factory); }
972 /// Remove this grid type from the registry.
974
975 /// @}
976
977
978private:
979 /// Deep copy metadata, but share tree and transform.
980 Grid(TreePtrType tree, const MetaMap& meta, math::Transform::Ptr xform);
981
982 /// Helper function for use with registerGrid()
983 static GridBase::Ptr factory() { return Grid::create(); }
984
985 TreePtrType mTree;
986}; // class Grid
987
988
989////////////////////////////////////////
990
991
992/// @brief Cast a generic grid pointer to a pointer to a grid of a concrete class.
993///
994/// Return a null pointer if the input pointer is null or if it
995/// points to a grid that is not of type @c GridType.
996///
997/// @note Calling gridPtrCast<GridType>(grid) is equivalent to calling
998/// GridBase::grid<GridType>(grid).
999template<typename GridType>
1000inline typename GridType::Ptr
1002{
1003 return GridBase::grid<GridType>(grid);
1004}
1005
1006
1007/// @brief Cast a generic const grid pointer to a const pointer to a grid
1008/// of a concrete class.
1009///
1010/// Return a null pointer if the input pointer is null or if it
1011/// points to a grid that is not of type @c GridType.
1012///
1013/// @note Calling gridConstPtrCast<GridType>(grid) is equivalent to calling
1014/// GridBase::constGrid<GridType>(grid).
1015template<typename GridType>
1016inline typename GridType::ConstPtr
1018{
1019 return GridBase::constGrid<GridType>(grid);
1020}
1021
1022
1023////////////////////////////////////////
1024
1025
1026/// @{
1027/// @brief Return a pointer to a deep copy of the given grid, provided that
1028/// the grid's concrete type is @c GridType.
1029///
1030/// Return a null pointer if the input pointer is null or if it
1031/// points to a grid that is not of type @c GridType.
1032template<typename GridType>
1033inline typename GridType::Ptr
1035{
1036 if (!grid || !grid->isType<GridType>()) return typename GridType::Ptr();
1037 return gridPtrCast<GridType>(grid->deepCopyGrid());
1038}
1039
1040
1041template<typename GridType>
1042inline typename GridType::Ptr
1044{
1045 if (!grid.isType<GridType>()) return typename GridType::Ptr();
1046 return gridPtrCast<GridType>(grid.deepCopyGrid());
1047}
1048/// @}
1049
1050
1051////////////////////////////////////////
1052
1053
1054//@{
1055/// @brief This adapter allows code that is templated on a Tree type to
1056/// accept either a Tree type or a Grid type.
1057template<typename _TreeType>
1059{
1060 using TreeType = _TreeType;
1061 using NonConstTreeType = typename std::remove_const<TreeType>::type;
1062 using TreePtrType = typename TreeType::Ptr;
1063 using ConstTreePtrType = typename TreeType::ConstPtr;
1064 using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1067 using GridPtrType = typename GridType::Ptr;
1070 using ValueType = typename TreeType::ValueType;
1074
1075 static NonConstTreeType& tree(NonConstTreeType& t) { return t; }
1076 static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); }
1077 static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; }
1078 static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); }
1079 static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; }
1080 static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); }
1081 static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; }
1082 static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); }
1083};
1084
1085
1086/// Partial specialization for Grid types
1087template<typename _TreeType>
1088struct TreeAdapter<Grid<_TreeType> >
1089{
1090 using TreeType = _TreeType;
1091 using NonConstTreeType = typename std::remove_const<TreeType>::type;
1092 using TreePtrType = typename TreeType::Ptr;
1093 using ConstTreePtrType = typename TreeType::ConstPtr;
1094 using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1097 using GridPtrType = typename GridType::Ptr;
1100 using ValueType = typename TreeType::ValueType;
1104
1105 static NonConstTreeType& tree(NonConstTreeType& t) { return t; }
1106 static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); }
1107 static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; }
1108 static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); }
1109 static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; }
1110 static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); }
1111 static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; }
1112 static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); }
1113};
1114
1115/// Partial specialization for const Grid types
1116template<typename _TreeType>
1117struct TreeAdapter<const Grid<_TreeType> >
1118{
1119 using TreeType = _TreeType;
1120 using NonConstTreeType = typename std::remove_const<TreeType>::type;
1121 using TreePtrType = typename TreeType::Ptr;
1122 using ConstTreePtrType = typename TreeType::ConstPtr;
1123 using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1126 using GridPtrType = typename GridType::Ptr;
1129 using ValueType = typename TreeType::ValueType;
1133
1134 static NonConstTreeType& tree(NonConstTreeType& t) { return t; }
1135 static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); }
1136 static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; }
1137 static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); }
1138 static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; }
1139 static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); }
1140 static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; }
1141 static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); }
1142};
1143
1144/// Partial specialization for ValueAccessor types
1145template<typename _TreeType>
1146struct TreeAdapter<tree::ValueAccessor<_TreeType> >
1147{
1148 using TreeType = _TreeType;
1149 using NonConstTreeType = typename std::remove_const<TreeType>::type;
1150 using TreePtrType = typename TreeType::Ptr;
1151 using ConstTreePtrType = typename TreeType::ConstPtr;
1152 using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1155 using GridPtrType = typename GridType::Ptr;
1158 using ValueType = typename TreeType::ValueType;
1162
1163 static NonConstTreeType& tree(NonConstTreeType& t) { return t; }
1164 static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); }
1165 static NonConstTreeType& tree(NonConstAccessorType& a) { return a.tree(); }
1166 static const NonConstTreeType& tree(ConstAccessorType& a) { return a.tree(); }
1167 static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; }
1168 static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); }
1169 static const NonConstTreeType& tree(const NonConstAccessorType& a) { return a.tree(); }
1170 static const NonConstTreeType& tree(const ConstAccessorType& a) { return a.tree(); }
1171 static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; }
1172 static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); }
1173 static const NonConstTreeType& constTree(NonConstAccessorType& a) { return a.tree(); }
1174 static const NonConstTreeType& constTree(ConstAccessorType& a) { return a.tree(); }
1175 static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; }
1176 static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); }
1177 static const NonConstTreeType& constTree(const NonConstAccessorType& a) { return a.tree(); }
1178 static const NonConstTreeType& constTree(const ConstAccessorType& a) { return a.tree(); }
1179};
1180
1181//@}
1182
1183
1184////////////////////////////////////////
1185
1186
1187namespace points {
1188
1189template<typename T, Index Log2Dim> class PointDataLeafNode;
1190
1191/// @brief Type trait that evaluates to true only for @c PointDataLeafNode instantiations.
1192template<typename T>
1193struct IsPointDataLeafNode : std::false_type {};
1194
1195template<typename T, Index Log2Dim>
1196struct IsPointDataLeafNode<PointDataLeafNode<T, Log2Dim>> : std::true_type {};
1197
1198} // namespace points
1199
1200
1201/// @brief Metafunction that specifies whether a given leaf node, tree, or grid type
1202/// requires multiple passes to read and write voxel data.
1203/// @details Multi-pass I/O allows leaf nodes to optimize their serialization layout
1204/// for delayed-load access patterns. Only @c PointDataLeafNode supports multi-pass I/O.
1205/// Defining a custom leaf node that inherits @c io::PointDataGridMultiPass is no longer permitted.
1206/// @sa points::IsPointDataLeafNode
1207template<typename LeafNodeType>
1209 static_assert(
1210 !std::is_base_of<io::PointDataGridMultiPass, LeafNodeType>::value
1212 "Only PointDataLeafNode may inherit from io::PointDataGridMultiPass; "
1213 "use points::IsPointDataLeafNode to test for multi-pass I/O support.");
1215};
1216
1217// Partial specialization for Tree types
1218template<typename RootNodeType>
1219struct HasMultiPassIO<tree::Tree<RootNodeType>> {
1220 // A tree is multi-pass if its (root node's) leaf node type is multi-pass.
1222};
1223
1224// Partial specialization for Grid types
1225template<typename TreeType>
1226struct HasMultiPassIO<Grid<TreeType>> {
1227 // A grid is multi-pass if its tree's leaf node type is multi-pass.
1229};
1230
1231
1232////////////////////////////////////////
1233
1235 : MetaMap(meta)
1236 , mTransform(xform)
1237{
1238 if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
1239}
1240
1241template<typename GridType>
1242inline typename GridType::Ptr
1244{
1245 // The string comparison on type names is slower than a dynamic pointer cast, but
1246 // it is safer when pointers cross DSO boundaries, as they do in many Houdini nodes.
1247 if (grid && grid->type() == GridType::gridType()) {
1249 }
1250 return typename GridType::Ptr();
1251}
1252
1253
1254template<typename GridType>
1255inline typename GridType::ConstPtr
1261
1262
1263template<typename GridType>
1264inline typename GridType::ConstPtr
1269
1270
1271template<typename GridType>
1272inline typename GridType::ConstPtr
1278
1279
1280inline TreeBase::Ptr
1285
1286
1287inline void
1289{
1290 if (!xform) OPENVDB_THROW(ValueError, "Transform pointer is null");
1291 mTransform = xform;
1292}
1293
1294
1295////////////////////////////////////////
1296
1297
1298template<typename TreeT>
1299inline Grid<TreeT>::Grid(): mTree(new TreeType)
1300{
1301}
1302
1303
1304template<typename TreeT>
1306{
1307}
1308
1309
1310template<typename TreeT>
1312{
1313 if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1314}
1315
1316
1317template<typename TreeT>
1318inline Grid<TreeT>::Grid(TreePtrType tree, const MetaMap& meta, math::Transform::Ptr xform):
1319 GridBase(meta, xform),
1320 mTree(tree)
1321{
1322 if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1323}
1324
1325
1326template<typename TreeT>
1327inline Grid<TreeT>::Grid(const Grid& other):
1328 GridBase(other),
1329 mTree(StaticPtrCast<TreeType>(other.mTree->copy()))
1330{
1331}
1332
1333
1334template<typename TreeT>
1335template<typename OtherTreeType>
1337 GridBase(other),
1338 mTree(new TreeType(other.constTree()))
1339{
1340}
1341
1342
1343template<typename TreeT>
1345 GridBase(other),
1346 mTree(other.mTree)
1347{
1348}
1349
1350
1351template<typename TreeT>
1352inline Grid<TreeT>::Grid(const GridBase& other):
1353 GridBase(other),
1354 mTree(new TreeType)
1355{
1356}
1357
1358
1359//static
1360template<typename TreeT>
1361inline typename Grid<TreeT>::Ptr
1366
1367
1368//static
1369template<typename TreeT>
1370inline typename Grid<TreeT>::Ptr
1372{
1373 return Ptr(new Grid(background));
1374}
1375
1376
1377//static
1378template<typename TreeT>
1379inline typename Grid<TreeT>::Ptr
1381{
1382 return Ptr(new Grid(tree));
1383}
1384
1385
1386//static
1387template<typename TreeT>
1388inline typename Grid<TreeT>::Ptr
1390{
1391 return Ptr(new Grid(other));
1392}
1393
1394
1395////////////////////////////////////////
1396
1397
1398template<typename TreeT>
1399inline typename Grid<TreeT>::ConstPtr
1401{
1402 return ConstPtr{new Grid{*const_cast<Grid*>(this), ShallowCopy{}}};
1403}
1404
1405
1406template<typename TreeT>
1407inline typename Grid<TreeT>::ConstPtr
1415
1416template<typename TreeT>
1417inline typename Grid<TreeT>::ConstPtr
1422
1423template<typename TreeT>
1424inline typename Grid<TreeT>::ConstPtr
1426 math::Transform::Ptr xform) const
1427{
1429 return ConstPtr{new Grid<TreeT>{treePtr, meta, xform}};
1430}
1431
1432
1433template<typename TreeT>
1434inline typename Grid<TreeT>::Ptr
1436{
1437 return Ptr{new Grid{*this, ShallowCopy{}}};
1438}
1439
1440
1441template<typename TreeT>
1442inline typename Grid<TreeT>::Ptr
1444{
1445 Ptr result{new Grid{*const_cast<Grid*>(this), ShallowCopy{}}};
1446 result->newTree();
1447 return result;
1448}
1449
1450
1451template<typename TreeT>
1452inline GridBase::Ptr
1454{
1455 return this->copy();
1456}
1457
1458template<typename TreeT>
1459inline GridBase::ConstPtr
1461{
1462 return this->copy();
1463}
1464
1465template<typename TreeT>
1466inline GridBase::ConstPtr
1468{
1469 return this->copyReplacingMetadata(meta);
1470}
1471
1472template<typename TreeT>
1473inline GridBase::ConstPtr
1478
1479template<typename TreeT>
1480inline GridBase::ConstPtr
1482 math::Transform::Ptr xform) const
1483{
1484 return this->copyReplacingMetadataAndTransform(meta, xform);
1485}
1486
1487template<typename TreeT>
1488inline GridBase::Ptr
1490{
1491 return this->copyWithNewTree();
1492}
1493
1494
1495////////////////////////////////////////
1496
1497
1498template<typename TreeT>
1499inline bool
1501{
1502 return mTree.use_count() == 1;
1503}
1504
1505
1506template<typename TreeT>
1507inline void
1509{
1510 if (!tree) OPENVDB_THROW(ValueError, "Tree pointer is null");
1511 if (tree->type() != TreeType::treeType()) {
1512 OPENVDB_THROW(TypeError, "Cannot assign a tree of type "
1513 + tree->type() + " to a grid of type " + this->type());
1514 }
1516}
1517
1518
1519template<typename TreeT>
1520inline void
1522{
1523 mTree.reset(new TreeType(this->background()));
1524}
1525
1526
1527////////////////////////////////////////
1528
1529
1530template<typename TreeT>
1531inline void
1532Grid<TreeT>::sparseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1533{
1534 tree().sparseFill(bbox, value, active);
1535}
1536
1537
1538template<typename TreeT>
1539inline void
1540Grid<TreeT>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1541{
1542 this->sparseFill(bbox, value, active);
1543}
1544
1545template<typename TreeT>
1546inline void
1547Grid<TreeT>::denseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1548{
1549 tree().denseFill(bbox, value, active);
1550}
1551
1552template<typename TreeT>
1553inline void
1555{
1556 const auto value = math::cwiseAdd(zeroVal<ValueType>(), tolerance);
1557 this->tree().prune(static_cast<ValueType>(value));
1558}
1559
1560template<typename TreeT>
1561inline void
1563{
1564 tree().clip(bbox);
1565}
1566
1567template<typename TreeT>
1568inline void
1570{
1571 tree().merge(other.tree(), policy);
1572}
1573
1574
1575template<typename TreeT>
1576template<typename OtherTreeType>
1577inline void
1579{
1580 tree().topologyUnion(other.tree());
1581}
1582
1583
1584template<typename TreeT>
1585template<typename OtherTreeType>
1586inline void
1588{
1589 tree().topologyIntersection(other.tree());
1590}
1591
1592
1593template<typename TreeT>
1594template<typename OtherTreeType>
1595inline void
1597{
1598 tree().topologyDifference(other.tree());
1599}
1600
1601
1602////////////////////////////////////////
1603
1604
1605template<typename TreeT>
1606inline CoordBBox
1608{
1609 CoordBBox bbox;
1610 tree().evalActiveVoxelBoundingBox(bbox);
1611 return bbox;
1612}
1613
1614
1615template<typename TreeT>
1616inline Coord
1618{
1619 Coord dim;
1620 const bool nonempty = tree().evalActiveVoxelDim(dim);
1621 return (nonempty ? dim : Coord());
1622}
1623
1624
1625////////////////////////////////////////
1626
1627#if OPENVDB_ABI_VERSION_NUMBER < 14
1628
1629/// @internal Consider using the stream tagging mechanism (see io::Archive)
1630/// to specify the float precision, but note that the setting is per-grid.
1631
1632template<typename TreeT>
1633inline void
1634Grid<TreeT>::readTopology(std::istream& is)
1635{
1636 tree().readTopology(is, saveFloatAsHalf());
1637 // When called from the legacy (non-codec) TopologyOnly path, the stream
1638 // metadata carries a flag requesting that leaf buffers be allocated and
1639 // filled with the background value (PartialCreate leaves them
1640 // unallocated after readTopology).
1642 if (meta->allocateLeafBuffers()) {
1643 meta->setAllocateLeafBuffers(false);
1644 if constexpr (!std::is_void_v<typename TreeT::LeafNodeType>) {
1645 const auto background = tree().root().background();
1646 tree::LeafManager<TreeT> leafManager(tree());
1647 leafManager.foreach([&background](auto& leaf, size_t) {
1648 using LeafType = std::decay_t<decltype(leaf)>;
1649 if constexpr (!std::is_same_v<typename LeafType::ValueType, bool>) {
1650 if (leaf.buffer().empty()) {
1651 leaf.buffer().allocate();
1652 leaf.buffer().fill(background);
1653 }
1654 }
1655 });
1656 }
1657 }
1658 }
1659}
1660
1661
1662template<typename TreeT>
1663inline void
1664Grid<TreeT>::writeTopology(std::ostream& os) const
1665{
1666 tree().writeTopology(os, saveFloatAsHalf());
1667}
1668
1669
1670template<typename TreeT>
1671inline void
1672Grid<TreeT>::readBuffers(std::istream& is)
1673{
1675
1676 if (!hasMultiPassIO()) {
1677 tree().readBuffers(is, saveFloatAsHalf());
1678 } else {
1679 uint16_t numPasses = 1;
1680 is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
1682 OPENVDB_ASSERT(bool(meta));
1683 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1684 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1685 meta->setPass(pass);
1686 tree().readBuffers(is, saveFloatAsHalf());
1687 }
1688 }
1689}
1690
1691
1692/// @todo Refactor this and the readBuffers() above
1693/// once support for ABI 2 compatibility is dropped.
1694template<typename TreeT>
1695inline void
1696Grid<TreeT>::readBuffers(std::istream& is, const CoordBBox& bbox)
1697{
1699
1700 if (!hasMultiPassIO()) {
1701 tree().readBuffers(is, bbox, saveFloatAsHalf());
1702 } else {
1703 uint16_t numPasses = 1;
1704 is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
1706 OPENVDB_ASSERT(bool(meta));
1707 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1708 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1709 meta->setPass(pass);
1710 tree().readBuffers(is, saveFloatAsHalf());
1711 }
1712 // Cannot clip inside readBuffers() when using multiple passes,
1713 // so instead clip afterwards.
1714 tree().clip(bbox);
1715 }
1716}
1717
1718
1719template<typename TreeT>
1720inline void
1721Grid<TreeT>::writeBuffers(std::ostream& os) const
1722{
1723 if (!hasMultiPassIO()) {
1724 tree().writeBuffers(os, saveFloatAsHalf());
1725 } else {
1726 // Determine how many leaf buffer passes are required for this grid
1728 OPENVDB_ASSERT(bool(meta));
1729 uint16_t numPasses = 1;
1730 meta->setCountingPasses(true);
1731 meta->setPass(0);
1732 tree().writeBuffers(os, saveFloatAsHalf());
1733 numPasses = static_cast<uint16_t>(meta->pass());
1734 os.write(reinterpret_cast<const char*>(&numPasses), sizeof(uint16_t));
1735 meta->setCountingPasses(false);
1736
1737 // Save out the data blocks of the grid.
1738 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1739 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1740 meta->setPass(pass);
1741 tree().writeBuffers(os, saveFloatAsHalf());
1742 }
1743 }
1744}
1745
1746#endif // OPENVDB_ABI_VERSION_NUMBER < 14
1747
1748
1749//static
1750template<typename TreeT>
1751inline bool
1756
1757
1758template<typename TreeT>
1759inline void
1760Grid<TreeT>::print(std::ostream& os, int verboseLevel) const
1761{
1762 tree().print(os, verboseLevel);
1763
1764 if (metaCount() > 0) {
1765 os << "Additional metadata:" << std::endl;
1766 for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1767 os << " " << it->first;
1768 if (it->second) {
1769 const std::string value = it->second->str();
1770 if (!value.empty()) os << ": " << value;
1771 }
1772 os << "\n";
1773 }
1774 }
1775
1776 os << "Transform:" << std::endl;
1777 transform().print(os, /*indent=*/" ");
1778 os << std::endl;
1779}
1780
1781
1782////////////////////////////////////////
1783
1784
1785template<typename GridType>
1786inline typename GridType::Ptr
1787createGrid(const typename GridType::ValueType& background)
1788{
1789 return GridType::create(background);
1790}
1791
1792
1793template<typename GridType>
1794inline typename GridType::Ptr
1796{
1797 return GridType::create();
1798}
1799
1800
1801template<typename TreePtrType>
1803createGrid(TreePtrType tree)
1804{
1805 using TreeType = typename TreePtrType::element_type;
1807}
1808
1809
1810template<typename GridType>
1811typename GridType::Ptr
1812createLevelSet(Real voxelSize, Real halfWidth)
1813{
1814 using ValueType = typename GridType::ValueType;
1815
1816 // GridType::ValueType is required to be a floating-point scalar.
1818 "level-set grids must be floating-point-valued");
1819
1820 typename GridType::Ptr grid = GridType::create(
1821 /*background=*/static_cast<ValueType>(voxelSize * halfWidth));
1822 grid->setTransform(math::Transform::createLinearTransform(voxelSize));
1823 grid->setGridClass(GRID_LEVEL_SET);
1824 return grid;
1825}
1826
1827
1828////////////////////////////////////////
1829
1830
1831template<typename GridTypeListT, typename OpT>
1832inline bool
1833GridBase::apply(OpT& op) const
1834{
1835 return GridTypeListT::template apply<OpT&, const GridBase>(std::ref(op), *this);
1836}
1837
1838template<typename GridTypeListT, typename OpT>
1839inline bool
1841{
1842 return GridTypeListT::template apply<OpT&, GridBase>(std::ref(op), *this);
1843}
1844
1845template<typename GridTypeListT, typename OpT>
1846inline bool
1847GridBase::apply(const OpT& op) const
1848{
1849 return GridTypeListT::template apply<const OpT&, const GridBase>(std::ref(op), *this);
1850}
1851
1852template<typename GridTypeListT, typename OpT>
1853inline bool
1854GridBase::apply(const OpT& op)
1855{
1856 return GridTypeListT::template apply<const OpT&, GridBase>(std::ref(op), *this);
1857}
1858
1859
1860} // namespace OPENVDB_VERSION_NAME
1861} // namespace openvdb
1862
1863#endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
#define OPENVDB_API
Definition Platform.h:286
#define OPENVDB_DEPRECATED_MESSAGE(msg)
Definition Platform.h:158
Abstract base class for typed grids.
Definition Grid.h:79
virtual Name valueType() const =0
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
virtual GridBase::Ptr copyGrid()=0
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
virtual GridBase::ConstPtr copyGridReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const =0
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
virtual GridBase::ConstPtr copyGridReplacingMetadata(const MetaMap &meta) const =0
Return a new grid of the same type as this grid whose tree and transform is shared with this grid and...
static const char *const META_FILE_MEM_BYTES
Definition Grid.h:361
Ptr(*)() GridFactory
Definition Grid.h:84
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:1243
static const char *const META_FILE_BBOX_MAX
Definition Grid.h:359
static std::string gridClassToMenuName(GridClass)
Return a formatted string version of the grid class.
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition Grid.h:436
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition Grid.h:405
void setSaveFloatAsHalf(bool)
Return this grid's user-specified name.
~GridBase() override
Definition Grid.h:87
virtual GridBase::ConstPtr copyGridReplacingTransform(math::Transform::Ptr xform) const =0
Return a new grid of the same type as this grid whose tree is shared with this grid,...
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition Grid.h:440
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition Grid.h:431
static std::string vecTypeDescription(VecType)
Return a string describing how the given type of vector data is affected by transformations (e....
const math::Transform & constTransform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition Grid.h:414
void setName(const std::string &)
Specify a name for this grid.
static const char *const META_FILE_DELAYED_LOAD
Definition Grid.h:363
bool apply(const OpT &) const
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid.
Definition Grid.h:1847
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
Definition Grid.h:438
void clearGridClass()
Remove the setting specifying the class of this grid's volumetric data.
virtual bool isTreeUnique() const =0
Return true if tree is not shared with another grid.
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition Grid.h:147
static std::string vecTypeToString(VecType)
Return the metadata string value for the given type of vector data.
static const char *const META_IS_LOCAL_SPACE
Definition Grid.h:356
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
Definition Grid.h:442
SharedPtr< const GridBase > ConstPtr
Definition Grid.h:82
virtual GridBase::Ptr copyGridWithNewTree() const =0
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
Definition Grid.h:412
GridBase(GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition Grid.h:492
static const char *const META_SAVE_HALF_FLOAT
Definition Grid.h:355
static GridType::ConstPtr constGrid(const GridBase::ConstPtr &)
Definition Grid.h:1273
bool apply(OpT &)
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid.
Definition Grid.h:1840
virtual void clear()=0
Empty this grid, setting all voxels to the background.
void setGridClass(GridClass)
Specify the class of volumetric data (level set, fog volume, etc.) that is stored in this grid.
static GridType::ConstPtr grid(const GridBase::ConstPtr &)
Definition Grid.h:1256
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:172
void addStatsMetadata()
Add metadata to this grid comprising the current values of statistics like the active voxel count and...
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition Grid.h:189
void clearVectorType()
Remove the setting specifying the type of vector data stored in this grid.
virtual void newTree()=0
Set a new tree with the same background value as the previous tree.
static const char *const META_FILE_COMPRESSION
Definition Grid.h:360
virtual TreeBase::ConstPtr constBaseTreePtr() const =0
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
static std::string vecTypeExamples(VecType)
void clipGrid(const BBoxd &)
Clip this grid to the given world-space bounding box.
virtual CoordBBox evalActiveVoxelBoundingBox() const =0
static const char *const META_FILE_BBOX_MIN
Definition Grid.h:358
virtual Index64 memUsage() const =0
Return the number of bytes of memory used by this grid.
void setVectorType(VecType)
Specify the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this ...
virtual Index64 activeVoxelCount() const =0
Return the number of active voxels.
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition Grid.h:434
std::string getName() const
Return this grid's user-specified name.
bool apply(const OpT &)
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid.
Definition Grid.h:1854
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const =0
Output a human-readable description of this grid.
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform.
Definition Grid.h:1288
virtual void pruneGrid(float tolerance=0.0)=0
Reduce the memory footprint of this grid by increasing its sparseness either losslessly (tolerance = ...
bool apply(OpT &) const
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid.
Definition Grid.h:1833
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Definition Grid.h:1265
GridClass getGridClass() const
Return the class of volumetric data (level set, fog volume, etc.) that is stored in this grid.
static VecType stringToVecType(const std::string &)
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
static const char *const META_GRID_CREATOR
Definition Grid.h:353
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition Grid.h:470
static const char *const META_GRID_NAME
Definition Grid.h:354
static const char *const META_GRID_CLASS
Definition Grid.h:352
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition Grid.h:489
math::Transform::Ptr transformPtr()
Return a pointer to this grid's transform, which might be shared with other grids.
Definition Grid.h:403
static const char *const META_VECTOR_TYPE
Definition Grid.h:357
static GridClass stringToGridClass(const std::string &)
Return the class of volumetric data specified by the given string.
virtual Coord evalActiveVoxelDim() const =0
Return the dimensions of the axis-aligned bounding box of all active voxels.
void setCreator(const std::string &)
Provide a description of this grid's creator.
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
MetaMap::Ptr getStatsMetadata() const
Return a new MetaMap containing just the metadata that was added to this grid with addStatsMetadata.
const math::Transform & transform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition Grid.h:413
static std::string gridClassToString(GridClass)
Return the metadata string value for the given class of volumetric data.
virtual void clip(const CoordBBox &)=0
Clip this grid to the given index-space bounding box.
virtual Name type() const =0
Return the name of this grid's type.
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition Grid.h:184
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition Grid.h:194
static void clearRegistry()
Clear the grid type registry.
std::string getCreator() const
Return the user-specified description of this grid's creator.
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition Grid.h:472
VecType getVectorType() const
Return the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this g...
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
SharedPtr< GridBase > Ptr
Definition Grid.h:81
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
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:1281
virtual bool empty() const =0
Return true if this grid contains only background voxels.
static const char *const META_FILE_VOXEL_COUNT
Definition Grid.h:362
virtual void setTree(TreeBase::Ptr)=0
Associate the given tree with this grid, in place of its existing tree.
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
virtual GridBase::ConstPtr copyGrid() const =0
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
GridBase()
Initialize with an identity linear transform.
Definition Grid.h:482
bool isInWorldSpace() const
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition Grid.h:404
void setIsInWorldSpace(bool)
Specify whether this grid's voxel values are in world space or in local space.
Container class that associates a tree with a transform and metadata.
Definition Grid.h:571
const TreeType & tree() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition Grid.h:907
typename _TreeType::Ptr TreePtrType
Definition Grid.h:577
Grid()
Construct a new grid with background value zero.
Definition Grid.h:1299
typename _TreeType::ValueOffCIter ValueOffCIter
Definition Grid.h:585
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition Grid.h:725
typename _TreeType::ValueOffIter ValueOffIter
Definition Grid.h:584
void topologyIntersection(const Grid< OtherTreeType > &other)
Intersect this grid's set of active values with the active values of the other grid,...
Definition Grid.h:1587
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition Grid.h:765
Index64 memUsage() const override
Definition Grid.h:881
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers.
Definition Grid.h:1752
ConstPtr copyReplacingTransform(math::Transform::Ptr xform) const
Return a new grid of the same type as this grid whose tree is shared with this grid,...
Definition Grid.h:1418
Grid(const Grid &)
Deep copy another grid's metadata, transform and tree.
Definition Grid.h:1327
Ptr copy()
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition Grid.h:1435
bool isTreeUnique() const final
Return true if tree is not shared with another grid.
Definition Grid.h:1500
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition Grid.h:1554
static Ptr create(const ValueType &background)
Return a new grid with the given background value.
Definition Grid.h:1371
static Ptr create(const GridBase &other)
Return a new, empty grid with the same transform and metadata as the given grid and with background v...
Definition Grid.h:1389
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition Grid.h:1562
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition Grid.h:771
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:894
Grid(Grid &, ShallowCopy)
Deep copy another grid's metadata and transform, but share its tree.
Definition Grid.h:1344
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition Grid.h:1617
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition Grid.h:757
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition Grid.h:1508
Ptr copyWithNewTree() const
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition Grid.h:1443
Grid(const ValueType &background)
Construct a new grid with the given background value.
Definition Grid.h:1305
GridBase::Ptr copyGridWithNewTree() const override
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition Grid.h:1489
typename _TreeType::Accessor Accessor
Definition Grid.h:589
~Grid() override
Definition Grid.h:640
Name type() const override
Return the name of this grid's type.
Definition Grid.h:709
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition Grid.h:1760
GridBase::ConstPtr copyGridReplacingMetadata(const MetaMap &meta) const override
Return a new grid of the same type as this grid whose tree and transform is shared with this grid and...
Definition Grid.h:1467
typename _TreeType::ValueAllCIter ValueAllCIter
Definition Grid.h:587
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition Grid.h:873
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition Grid.h:742
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition Grid.h:703
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:1540
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition Grid.h:763
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels.
Definition Grid.h:740
GridBase::Ptr copyGrid() override
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
Definition Grid.h:1453
typename _TreeType::ValueType ValueType
Definition Grid.h:579
typename _TreeType::ConstPtr ConstTreePtrType
Definition Grid.h:578
ConstPtr copy() const
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition Grid.h:1400
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Definition Grid.h:755
typename _TreeType::ValueOnCIter ValueOnCIter
Definition Grid.h:583
SharedPtr< const Grid > ConstPtr
Definition Grid.h:574
static void registerGrid()
Register this grid type along with a factory function.
Definition Grid.h:971
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition Grid.h:759
typename _TreeType::UnsafeAccessor UnsafeAccessor
Definition Grid.h:591
ConstPtr copyReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
Definition Grid.h:1425
static bool isRegistered()
Return true if this grid type is registered.
Definition Grid.h:969
typename _TreeType::ValueOnIter ValueOnIter
Definition Grid.h:582
typename _TreeType::ConstAccessor ConstAccessor
Definition Grid.h:590
GridBase::ConstPtr copyGridReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const override
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
Definition Grid.h:1481
typename _TreeType::ConstUnsafeAccessor ConstUnsafeAccessor
Definition Grid.h:592
typename _TreeType::BuildType BuildType
Definition Grid.h:580
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition Grid.h:744
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value and ensure that those voxels are a...
Definition Grid.h:1547
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:893
void topologyDifference(const Grid< OtherTreeType > &other)
Difference this grid's set of active values with the active values of the other grid,...
Definition Grid.h:1596
TreeBase::ConstPtr constBaseTreePtr() const override
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition Grid.h:895
Grid(TreePtrType)
Construct a new grid that shares the given tree and associates with it an identity linear transform.
Definition Grid.h:1311
GridBase::ConstPtr copyGridReplacingTransform(math::Transform::Ptr xform) const override
Return a new grid of the same type as this grid whose tree is shared with this grid,...
Definition Grid.h:1474
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition Grid.h:1607
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition Grid.h:701
GridBase::ConstPtr copyGrid() const override
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
Definition Grid.h:1460
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition Grid.h:761
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:1532
TreePtrType treePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition Grid.h:892
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition Grid.h:1569
static void unregisterGrid()
Remove this grid type from the registry.
Definition Grid.h:973
ConstPtr copyReplacingMetadata(const MetaMap &meta) const
Return a new grid of the same type as this grid whose tree and transform is shared with this grid and...
Definition Grid.h:1408
typename _TreeType::ValueAllIter ValueAllIter
Definition Grid.h:586
_TreeType TreeType
Definition Grid.h:576
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition Grid.h:714
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition Grid.h:727
Grid(const GridBase &)
Deep copy another grid's metadata and transform, but construct a new tree with background value zero.
Definition Grid.h:1352
const TreeType & constTree() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition Grid.h:908
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition Grid.h:769
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition Grid.h:1521
Grid & operator=(const Grid &)=delete
Disallow assignment, since it wouldn't be obvious whether the copy is deep or shallow.
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
Definition Grid.h:752
static Ptr create(TreePtrType)
Return a new grid that contains the given tree.
Definition Grid.h:1380
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:1578
SharedPtr< Grid > Ptr
Definition Grid.h:573
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition Grid.h:732
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
Definition Grid.h:767
static Ptr create()
Return a new grid with background value zero.
Definition Grid.h:1362
Grid(const Grid< OtherTreeType > &)
Deep copy the metadata, transform and tree of another grid whose tree configuration is the same as th...
Definition Grid.h:1336
Container that maps names (strings) to values of arbitrary types.
Definition MetaMap.h:20
size_t metaCount() const
Definition MetaMap.h:91
MetaIterator beginMeta()
Definition MetaMap.h:84
MetadataMap::const_iterator ConstMetaIterator
Definition MetaMap.h:27
SharedPtr< MetaMap > Ptr
Definition MetaMap.h:22
MetaIterator endMeta()
Definition MetaMap.h:85
MetaMap()
Definition MetaMap.h:30
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition Types.h:751
Definition Exceptions.h:64
Definition Exceptions.h:65
SharedPtr< StreamMetadata > Ptr
Definition io.h:31
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
Definition Transform.h:40
SharedPtr< const Transform > ConstPtr
Definition Transform.h:43
SharedPtr< Transform > Ptr
Definition Transform.h:42
static Transform::Ptr createLinearTransform(double voxelSize=1.0)
Create and return a shared pointer to a new transform.
Definition PointDataGrid.h:95
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition LeafManager.h:86
Base class for typed trees.
Definition Tree.h:38
SharedPtr< TreeBase > Ptr
Definition Tree.h:40
SharedPtr< const TreeBase > ConstPtr
Definition Tree.h:41
void checkFormatVersion(std::ios_base &)
Throws an IoError if the file format version number is not supported.
SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
Definition Types.h:763
Vec3< double > Vec3d
Definition Vec3.h:708
auto cwiseAdd(const Vec3H &v, const float s)
Definition Types.h:765
Definition Grid.h:1187
Definition PointDataGrid.h:48
ValueAccessorImpl< TreeType, IsSafe, MutexType, openvdb::make_index_sequence< CacheLevels > > ValueAccessor
Default alias for a ValueAccessor. This is simply a helper alias for the generic definition but takes...
Definition ValueAccessor.h:86
std::string Name
Definition Name.h:19
static const Real LEVEL_SET_HALF_WIDTH
Definition Types.h:532
GridPtrVec::const_iterator GridPtrVecCIter
Definition Grid.h:510
std::vector< GridBase::Ptr > GridPtrVec
Definition Grid.h:508
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition Grid.h:521
GridCPtrSet::iterator GridCPtrSetIter
Definition Grid.h:524
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition Grid.h:526
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:1017
double Real
Definition Types.h:40
GridClass
Definition Types.h:524
@ GRID_LEVEL_SET
Definition Types.h:526
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:1001
std::set< GridBase::ConstPtr > GridCPtrSet
Definition Grid.h:523
GridPtrContainerT::value_type findGridByName(const GridPtrContainerT &container, const Name &name)
Return the first grid in the given container whose name is name.
Definition Grid.h:540
std::set< GridBase::Ptr > GridPtrSet
Definition Grid.h:518
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition Grid.h:516
GridCPtrVec::iterator GridCPtrVecIter
Definition Grid.h:514
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:71
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition Grid.h:511
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition Grid.h:515
GridPtrSet::iterator GridPtrSetIter
Definition Grid.h:519
SharedPtr< T > ConstPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that points to the same object as the given pointer but with possibly dif...
Definition Types.h:107
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition Grid.h:525
math::BBox< Vec3d > BBoxd
Definition Types.h:65
GridPtrSet::const_iterator GridPtrSetCIter
Definition Grid.h:520
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:1812
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition Grid.h:1787
uint64_t Index64
Definition Types.h:33
tree::TreeBase TreeBase
Definition Grid.h:27
GridPtrVec::iterator GridPtrVecIter
Definition Grid.h:509
std::shared_ptr< T > SharedPtr
Definition Types.h:95
MergePolicy
Definition Types.h:577
@ MERGE_ACTIVE_STATES
Definition Types.h:578
VecType
Definition Types.h:554
SharedPtr< T > StaticPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that points to the same object as the given pointer after a static_cast.
Definition Types.h:127
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition Grid.h:513
GridType::Ptr deepCopyTypedGrid(const GridBase::ConstPtr &grid)
Return a pointer to a deep copy of the given grid, provided that the grid's concrete type is GridType...
Definition Grid.h:1034
GridType::Ptr createGrid()
Create a new grid of type GridType with background value zero.
Definition Grid.h:1795
Definition Exceptions.h:13
Definition Coord.h:590
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
Predicate functor that returns true for grids that have a specified name.
Definition Grid.h:531
Name name
Definition Grid.h:534
GridNamePred(const Name &_name)
Definition Grid.h:532
bool operator()(const GridBase::ConstPtr &g) const
Definition Grid.h:533
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition Grid.h:601
Grid< typename TreeType::template ValueConverter< OtherValueType >::Type > Type
Definition Grid.h:602
static const bool value
Definition Grid.h:1228
static const bool value
Definition Grid.h:1221
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition Grid.h:1208
static const bool value
Definition Grid.h:1214
static const NonConstTreeType & constTree(NonConstTreeType &t)
Definition Grid.h:1109
Grid< TreeType > GridType
Definition Grid.h:1095
typename std::remove_const< TreeType >::type NonConstTreeType
Definition Grid.h:1091
static const NonConstTreeType & constTree(const NonConstGridType &g)
Definition Grid.h:1112
typename TreeType::ValueType ValueType
Definition Grid.h:1100
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Definition Grid.h:1111
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition Grid.h:1103
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition Grid.h:1102
static const NonConstTreeType & tree(const NonConstGridType &g)
Definition Grid.h:1108
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition Grid.h:1094
typename TreeType::ConstPtr ConstTreePtrType
Definition Grid.h:1093
static NonConstTreeType & tree(NonConstTreeType &t)
Definition Grid.h:1105
static NonConstTreeType & tree(NonConstGridType &g)
Definition Grid.h:1106
typename GridType::Ptr GridPtrType
Definition Grid.h:1097
static const NonConstTreeType & constTree(NonConstGridType &g)
Definition Grid.h:1110
Grid< NonConstTreeType > NonConstGridType
Definition Grid.h:1096
typename GridType::ConstPtr ConstGridPtrType
Definition Grid.h:1099
typename TreeType::Ptr TreePtrType
Definition Grid.h:1092
static const NonConstTreeType & tree(const NonConstTreeType &t)
Definition Grid.h:1107
_TreeType TreeType
Definition Grid.h:1090
typename NonConstGridType::Ptr NonConstGridPtrType
Definition Grid.h:1098
typename tree::ValueAccessor< TreeType > AccessorType
Definition Grid.h:1101
static const NonConstTreeType & constTree(NonConstTreeType &t)
Definition Grid.h:1138
Grid< TreeType > GridType
Definition Grid.h:1124
typename std::remove_const< TreeType >::type NonConstTreeType
Definition Grid.h:1120
static const NonConstTreeType & constTree(const NonConstGridType &g)
Definition Grid.h:1141
typename TreeType::ValueType ValueType
Definition Grid.h:1129
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Definition Grid.h:1140
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition Grid.h:1132
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition Grid.h:1131
static const NonConstTreeType & tree(const NonConstGridType &g)
Definition Grid.h:1137
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition Grid.h:1123
typename TreeType::ConstPtr ConstTreePtrType
Definition Grid.h:1122
static NonConstTreeType & tree(NonConstTreeType &t)
Definition Grid.h:1134
static NonConstTreeType & tree(NonConstGridType &g)
Definition Grid.h:1135
typename GridType::Ptr GridPtrType
Definition Grid.h:1126
static const NonConstTreeType & constTree(NonConstGridType &g)
Definition Grid.h:1139
Grid< NonConstTreeType > NonConstGridType
Definition Grid.h:1125
typename GridType::ConstPtr ConstGridPtrType
Definition Grid.h:1128
typename TreeType::Ptr TreePtrType
Definition Grid.h:1121
static const NonConstTreeType & tree(const NonConstTreeType &t)
Definition Grid.h:1136
typename NonConstGridType::Ptr NonConstGridPtrType
Definition Grid.h:1127
typename tree::ValueAccessor< TreeType > AccessorType
Definition Grid.h:1130
static const NonConstTreeType & constTree(NonConstTreeType &t)
Definition Grid.h:1171
static NonConstTreeType & tree(NonConstAccessorType &a)
Definition Grid.h:1165
typename std::remove_const< TreeType >::type NonConstTreeType
Definition Grid.h:1149
typename tree::ValueAccessor< const NonConstTreeType > ConstAccessorType
Definition Grid.h:1160
static const NonConstTreeType & constTree(NonConstAccessorType &a)
Definition Grid.h:1173
static const NonConstTreeType & constTree(const NonConstGridType &g)
Definition Grid.h:1176
typename TreeType::ValueType ValueType
Definition Grid.h:1158
static const NonConstTreeType & constTree(const ConstAccessorType &a)
Definition Grid.h:1178
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Definition Grid.h:1175
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition Grid.h:1161
static const NonConstTreeType & tree(const ConstAccessorType &a)
Definition Grid.h:1170
static const NonConstTreeType & tree(const NonConstGridType &g)
Definition Grid.h:1168
static const NonConstTreeType & tree(const NonConstAccessorType &a)
Definition Grid.h:1169
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition Grid.h:1152
typename TreeType::ConstPtr ConstTreePtrType
Definition Grid.h:1151
static NonConstTreeType & tree(NonConstTreeType &t)
Definition Grid.h:1163
static NonConstTreeType & tree(NonConstGridType &g)
Definition Grid.h:1164
static const NonConstTreeType & tree(ConstAccessorType &a)
Definition Grid.h:1166
typename GridType::Ptr GridPtrType
Definition Grid.h:1155
static const NonConstTreeType & constTree(NonConstGridType &g)
Definition Grid.h:1172
static const NonConstTreeType & constTree(const NonConstAccessorType &a)
Definition Grid.h:1177
Grid< NonConstTreeType > NonConstGridType
Definition Grid.h:1154
typename GridType::ConstPtr ConstGridPtrType
Definition Grid.h:1157
typename TreeType::Ptr TreePtrType
Definition Grid.h:1150
static const NonConstTreeType & tree(const NonConstTreeType &t)
Definition Grid.h:1167
Grid< NonConstTreeType > GridType
Definition Grid.h:1153
typename NonConstGridType::Ptr NonConstGridPtrType
Definition Grid.h:1156
static const NonConstTreeType & constTree(ConstAccessorType &a)
Definition Grid.h:1174
typename tree::ValueAccessor< TreeType > AccessorType
Definition Grid.h:1159
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition Grid.h:1059
static const NonConstTreeType & constTree(NonConstTreeType &t)
Definition Grid.h:1079
typename std::remove_const< TreeType >::type NonConstTreeType
Definition Grid.h:1061
static const NonConstTreeType & constTree(const NonConstGridType &g)
Definition Grid.h:1082
typename TreeType::ValueType ValueType
Definition Grid.h:1070
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Definition Grid.h:1081
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition Grid.h:1073
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition Grid.h:1072
static const NonConstTreeType & tree(const NonConstGridType &g)
Definition Grid.h:1078
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition Grid.h:1064
typename TreeType::ConstPtr ConstTreePtrType
Definition Grid.h:1063
static NonConstTreeType & tree(NonConstTreeType &t)
Definition Grid.h:1075
static NonConstTreeType & tree(NonConstGridType &g)
Definition Grid.h:1076
typename GridType::Ptr GridPtrType
Definition Grid.h:1067
static const NonConstTreeType & constTree(NonConstGridType &g)
Definition Grid.h:1080
Grid< NonConstTreeType > NonConstGridType
Definition Grid.h:1066
typename GridType::ConstPtr ConstGridPtrType
Definition Grid.h:1069
typename TreeType::Ptr TreePtrType
Definition Grid.h:1062
static const NonConstTreeType & tree(const NonConstTreeType &t)
Definition Grid.h:1077
_TreeType TreeType
Definition Grid.h:1060
Grid< NonConstTreeType > GridType
Definition Grid.h:1065
typename NonConstGridType::Ptr NonConstGridPtrType
Definition Grid.h:1068
typename tree::ValueAccessor< TreeType > AccessorType
Definition Grid.h:1071
Definition Types.h:507
Type trait that evaluates to true only for PointDataLeafNode instantiations.
Definition Grid.h:1193
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:291