OpenVDB 12.0.0
 
Loading...
Searching...
No Matches
Dense.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4/// @file Dense.h
5///
6/// @brief This file defines a simple dense grid and efficient
7/// converters to and from VDB grids.
8
9#ifndef OPENVDB_TOOLS_DENSE_HAS_BEEN_INCLUDED
10#define OPENVDB_TOOLS_DENSE_HAS_BEEN_INCLUDED
11
12#include <openvdb/Types.h>
13#include <openvdb/Grid.h>
15#include <openvdb/Exceptions.h>
17#include <openvdb/util/Assert.h>
18#include "Prune.h"
19#include <tbb/parallel_for.h>
20#include <iostream>
21#include <memory>
22#include <string>
23#include <utility> // for std::pair
24#include <vector>
25
26namespace openvdb {
28namespace OPENVDB_VERSION_NAME {
29namespace tools {
30
31/// @brief Populate a dense grid with the values of voxels from a sparse grid,
32/// where the sparse grid intersects the dense grid.
33/// @param sparse an OpenVDB grid or tree from which to copy values
34/// @param dense the dense grid into which to copy values
35/// @param serial if false, process voxels in parallel
36template<typename DenseT, typename GridOrTreeT>
37void
39 const GridOrTreeT& sparse,
40 DenseT& dense,
41 bool serial = false);
42
43
44/// @brief Populate a sparse grid with the values of all of the voxels of a dense grid.
45/// @param dense the dense grid from which to copy values
46/// @param sparse an OpenVDB grid or tree into which to copy values
47/// @param tolerance values in the dense grid that are within this tolerance of the sparse
48/// grid's background value become inactive background voxels or tiles in the sparse grid
49/// @param serial if false, process voxels in parallel
50template<typename DenseT, typename GridOrTreeT>
51void
53 const DenseT& dense,
54 GridOrTreeT& sparse,
55 const typename GridOrTreeT::ValueType& tolerance,
56 bool serial = false);
57
58
59////////////////////////////////////////
60
61/// We currently support the following two 3D memory layouts for dense
62/// volumes: XYZ, i.e. x is the fastest moving index, and ZYX, i.e. z
63/// is the fastest moving index. The ZYX memory layout leads to nested
64/// for-loops of the order x, y, z, which we find to be the most
65/// intuitive. Hence, ZYX is the layout used throughout VDB. However,
66/// other data structures, e.g. Houdini and Maya, employ the XYZ
67/// layout. Clearly a dense volume with the ZYX layout converts more
68/// efficiently to a VDB, but we support both for convenience.
70
71/// @brief Base class for Dense which is defined below.
72/// @note The constructor of this class is protected to prevent direct
73/// instantiation.
74template<typename ValueT, MemoryLayout Layout> class DenseBase;
75
76/// @brief Partial template specialization of DenseBase.
77/// @note ZYX is the memory-layout in VDB. It leads to nested
78/// for-loops of the order x, y, z which we find to be the most intuitive.
79template<typename ValueT>
80class DenseBase<ValueT, LayoutZYX>
81{
82public:
83 /// @brief Return the linear offset into this grid's value array given by
84 /// unsigned coordinates (i, j, k), i.e., coordinates relative to
85 /// the origin of this grid's bounding box.
86 ///
87 /// @warning The input coordinates are assume to be relative to
88 /// the grid's origin, i.e. minimum of its index bounding box!
89 inline size_t coordToOffset(size_t i, size_t j, size_t k) const { return i*mX + j*mY + k; }
90
91 /// @brief Return the local coordinate corresponding to the specified linear offset.
92 ///
93 /// @warning The returned coordinate is relative to the origin of this
94 /// grid's bounding box so add dense.origin() to get absolute coordinates.
95 inline Coord offsetToLocalCoord(size_t n) const
96 {
97 const size_t x = n / mX;
98 n -= mX*x;
99 const size_t y = n / mY;
101 }
102
103 /// @brief Return the stride of the array in the x direction ( = dimY*dimZ).
104 /// @note This method is required by both CopyToDense and CopyFromDense.
105 inline size_t xStride() const { return mX; }
106
107 /// @brief Return the stride of the array in the y direction ( = dimZ).
108 /// @note This method is required by both CopyToDense and CopyFromDense.
109 inline size_t yStride() const { return mY; }
110
111 /// @brief Return the stride of the array in the z direction ( = 1).
112 /// @note This method is required by both CopyToDense and CopyFromDense.
113 static size_t zStride() { return 1; }
114
115protected:
116 /// Protected constructor so as to prevent direct instantiation
117 DenseBase(const CoordBBox& bbox) : mBBox(bbox), mY(bbox.dim()[2]), mX(mY*bbox.dim()[1]) {}
118
119 const CoordBBox mBBox;//signed coordinates of the domain represented by the grid
120 const size_t mY, mX;//strides in the y and x direction
121};// end of DenseBase<ValueT, LayoutZYX>
122
123/// @brief Partial template specialization of DenseBase.
124/// @note This is the memory-layout employed in Houdini and Maya. It leads
125/// to nested for-loops of the order z, y, x.
126template<typename ValueT>
127class DenseBase<ValueT, LayoutXYZ>
128{
129public:
130 /// @brief Return the linear offset into this grid's value array given by
131 /// unsigned coordinates (i, j, k), i.e., coordinates relative to
132 /// the origin of this grid's bounding box.
133 ///
134 /// @warning The input coordinates are assume to be relative to
135 /// the grid's origin, i.e. minimum of its index bounding box!
136 inline size_t coordToOffset(size_t i, size_t j, size_t k) const { return i + j*mY + k*mZ; }
137
138 /// @brief Return the index coordinate corresponding to the specified linear offset.
139 ///
140 /// @warning The returned coordinate is relative to the origin of this
141 /// grid's bounding box so add dense.origin() to get absolute coordinates.
142 inline Coord offsetToLocalCoord(size_t n) const
143 {
144 const size_t z = n / mZ;
145 n -= mZ*z;
146 const size_t y = n / mY;
148 }
149
150 /// @brief Return the stride of the array in the x direction ( = 1).
151 /// @note This method is required by both CopyToDense and CopyFromDense.
152 static size_t xStride() { return 1; }
153
154 /// @brief Return the stride of the array in the y direction ( = dimX).
155 /// @note This method is required by both CopyToDense and CopyFromDense.
156 inline size_t yStride() const { return mY; }
157
158 /// @brief Return the stride of the array in the y direction ( = dimX*dimY).
159 /// @note This method is required by both CopyToDense and CopyFromDense.
160 inline size_t zStride() const { return mZ; }
161
162protected:
163 /// Protected constructor so as to prevent direct instantiation
164 DenseBase(const CoordBBox& bbox) : mBBox(bbox), mY(bbox.dim()[0]), mZ(mY*bbox.dim()[1]) {}
165
166 const CoordBBox mBBox;//signed coordinates of the domain represented by the grid
167 const size_t mY, mZ;//strides in the y and z direction
168};// end of DenseBase<ValueT, LayoutXYZ>
169
170/// @brief Dense is a simple dense grid API used by the CopyToDense and
171/// CopyFromDense classes defined below.
172/// @details Use the Dense class to efficiently produce a dense in-memory
173/// representation of an OpenVDB grid. However, be aware that a dense grid
174/// could have a memory footprint that is orders of magnitude larger than
175/// the sparse grid from which it originates.
176///
177/// @note This class can be used as a simple wrapper for existing dense grid
178/// classes if they provide access to the raw data array.
179/// @note This implementation allows for the 3D memory layout to be
180/// defined by the MemoryLayout template parameter (see above for definition).
181/// The default memory layout is ZYX since that's the layout used by OpenVDB grids.
182template<typename ValueT, MemoryLayout Layout = LayoutZYX>
183class Dense : public DenseBase<ValueT, Layout>
184{
185public:
186 using ValueType = ValueT;
190
191 /// @brief Construct a dense grid with a given range of coordinates.
192 ///
193 /// @param bbox the bounding box of the (signed) coordinate range of this grid
194 /// @throw ValueError if the bounding box is empty.
195 /// @note The min and max coordinates of the bounding box are inclusive.
196 Dense(const CoordBBox& bbox) : BaseT(bbox) { this->init(); }
197
198 /// @brief Construct a dense grid with a given range of coordinates and initial value
199 ///
200 /// @param bbox the bounding box of the (signed) coordinate range of this grid
201 /// @param value the initial value of the grid.
202 /// @throw ValueError if the bounding box is empty.
203 /// @note The min and max coordinates of the bounding box are inclusive.
204 Dense(const CoordBBox& bbox, const ValueT& value) : BaseT(bbox)
205 {
206 this->init();
207 this->fill(value);
208 }
209
210 /// @brief Construct a dense grid that wraps an external array.
211 ///
212 /// @param bbox the bounding box of the (signed) coordinate range of this grid
213 /// @param data a raw C-style array whose size is commensurate with
214 /// the coordinate domain of @a bbox
215 ///
216 /// @note The data array is assumed to have a stride of one in the @e z direction.
217 /// @throw ValueError if the bounding box is empty.
218 /// @note The min and max coordinates of the bounding box are inclusive.
219 Dense(const CoordBBox& bbox, ValueT* data) : BaseT(bbox), mData(data)
220 {
221 if (BaseT::mBBox.empty()) {
222 OPENVDB_THROW(ValueError, "can't construct a dense grid with an empty bounding box");
223 }
224 }
225
226 /// @brief Construct a dense grid with a given origin and dimensions.
227 ///
228 /// @param dim the desired dimensions of the grid
229 /// @param min the signed coordinates of the first voxel in the dense grid
230 /// @throw ValueError if any of the dimensions are zero.
231 /// @note The @a min coordinate is inclusive, and the max coordinate will be
232 /// @a min + @a dim - 1.
233 Dense(const Coord& dim, const Coord& min = Coord(0))
234 : BaseT(CoordBBox(min, min+dim.offsetBy(-1)))
235 {
236 this->init();
237 }
238
239 /// @brief Return the memory layout for this grid (see above for definitions).
240 static MemoryLayout memoryLayout() { return Layout; }
241
242 /// @brief Return a raw pointer to this grid's value array.
243 /// @note This method is required by CopyToDense.
244 inline ValueT* data() { return mData; }
245
246 /// @brief Return a raw pointer to this grid's value array.
247 /// @note This method is required by CopyFromDense.
248 inline const ValueT* data() const { return mData; }
249
250 /// @brief Return the bounding box of the signed index domain of this grid.
251 /// @note This method is required by both CopyToDense and CopyFromDense.
252 inline const CoordBBox& bbox() const { return BaseT::mBBox; }
253
254 /// Return the grid's origin in index coordinates.
255 inline const Coord& origin() const { return BaseT::mBBox.min(); }
256
257 /// @brief Return the number of voxels contained in this grid.
258 inline Index64 valueCount() const { return BaseT::mBBox.volume(); }
259
260 /// @brief Set the value of the voxel at the given array offset.
261 inline void setValue(size_t offset, const ValueT& value) { mData[offset] = value; }
262
263 /// @brief Return a const reference to the value of the voxel at the given array offset.
264 const ValueT& getValue(size_t offset) const { return mData[offset]; }
265
266 /// @brief Return a non-const reference to the value of the voxel at the given array offset.
267 ValueT& getValue(size_t offset) { return mData[offset]; }
268
269 /// @brief Set the value of the voxel at unsigned index coordinates (i, j, k).
270 /// @note This is somewhat slower than using an array offset.
271 inline void setValue(size_t i, size_t j, size_t k, const ValueT& value)
272 {
273 mData[BaseT::coordToOffset(i,j,k)] = value;
274 }
275
276 /// @brief Return a const reference to the value of the voxel
277 /// at unsigned index coordinates (i, j, k).
278 /// @note This is somewhat slower than using an array offset.
279 inline const ValueT& getValue(size_t i, size_t j, size_t k) const
280 {
281 return mData[BaseT::coordToOffset(i,j,k)];
282 }
283
284 /// @brief Return a non-const reference to the value of the voxel
285 /// at unsigned index coordinates (i, j, k).
286 /// @note This is somewhat slower than using an array offset.
287 inline ValueT& getValue(size_t i, size_t j, size_t k)
288 {
289 return mData[BaseT::coordToOffset(i,j,k)];
290 }
291
292 /// @brief Set the value of the voxel at the given signed coordinates.
293 /// @note This is slower than using either an array offset or unsigned index coordinates.
294 inline void setValue(const Coord& xyz, const ValueT& value)
295 {
296 mData[this->coordToOffset(xyz)] = value;
297 }
298
299 /// @brief Return a const reference to the value of the voxel at the given signed coordinates.
300 /// @note This is slower than using either an array offset or unsigned index coordinates.
301 inline const ValueT& getValue(const Coord& xyz) const
302 {
303 return mData[this->coordToOffset(xyz)];
304 }
305
306 /// @brief Return a non-const reference to the value of the voxel
307 /// at the given signed coordinates.
308 /// @note This is slower than using either an array offset or unsigned index coordinates.
309 inline ValueT& getValue(const Coord& xyz)
310 {
311 return mData[this->coordToOffset(xyz)];
312 }
313
314 /// @brief Fill this grid with a constant value.
315 inline void fill(const ValueT& value)
316 {
317 size_t size = this->valueCount();
318 ValueT* a = mData;
319 while(size--) *a++ = value;
320 }
321
322 /// @brief Return the linear offset into this grid's value array given by
323 /// the specified signed coordinates, i.e., coordinates in the space of
324 /// this grid's bounding box.
325 ///
326 /// @note This method reflects the fact that we assume the same
327 /// layout of values as an OpenVDB grid, i.e., the fastest coordinate is @e z.
328 inline size_t coordToOffset(const Coord& xyz) const
329 {
330 OPENVDB_ASSERT(BaseT::mBBox.isInside(xyz));
331 return BaseT::coordToOffset(size_t(xyz[0]-BaseT::mBBox.min()[0]),
332 size_t(xyz[1]-BaseT::mBBox.min()[1]),
333 size_t(xyz[2]-BaseT::mBBox.min()[2]));
334 }
335
336 /// @brief Return the global coordinate corresponding to the specified linear offset.
337 inline Coord offsetToCoord(size_t n) const
338 {
339 return this->offsetToLocalCoord(n) + BaseT::mBBox.min();
340 }
341
342 /// @brief Return the memory footprint of this Dense grid in bytes.
343 inline Index64 memUsage() const
344 {
345 return sizeof(*this) + BaseT::mBBox.volume() * sizeof(ValueType);
346 }
347
348 /// @brief Output a human-readable description of this grid to the
349 /// specified stream.
350 void print(const std::string& name = "", std::ostream& os = std::cout) const
351 {
352 const Coord dim = BaseT::mBBox.dim();
353 os << "Dense Grid";
354 if (!name.empty()) os << " \"" << name << "\"";
355 util::printBytes(os, this->memUsage(), ":\n Memory footprint: ");
356 os << " Dimensions of grid : " << dim[0] << " x " << dim[1] << " x " << dim[2] << "\n";
357 os << " Number of voxels: " << util::formattedInt(this->valueCount()) << "\n";
358 os << " Bounding box of voxels: " << BaseT::mBBox << "\n";
359 os << " Memory layout: " << (Layout == LayoutZYX ? "ZYX (" : "XYZ (dis")
360 << "similar to VDB)\n";
361 }
362
363private:
364 /// @brief Private method to initialize the dense value array.
365 void init()
366 {
367 if (BaseT::mBBox.empty()) {
368 OPENVDB_THROW(ValueError, "can't construct a dense grid with an empty bounding box");
369 }
370 mArray.reset(new ValueT[BaseT::mBBox.volume()]);
371 mData = mArray.get();
372 }
373
374 std::unique_ptr<ValueT[]> mArray;
375 ValueT* mData;//raw c-style pointer to values
376};// end of Dense
377
378////////////////////////////////////////
379
380
381/// @brief Copy an OpenVDB tree into an existing dense grid.
382///
383/// @note Only voxels that intersect the dense grid's bounding box are copied
384/// from the OpenVDB tree. But both active and inactive voxels are copied,
385/// so all existing values in the dense grid are overwritten, regardless of
386/// the OpenVDB tree's topology.
387template<typename _TreeT, typename _DenseT = Dense<typename _TreeT::ValueType> >
389{
390public:
391 using DenseT = _DenseT;
392 using TreeT = _TreeT;
393 using ValueT = typename TreeT::ValueType;
394
395 CopyToDense(const TreeT& tree, DenseT& dense)
396 : mRoot(&(tree.root())), mDense(&dense) {}
397
398 void copy(bool serial = false) const
399 {
400 if (serial) {
401 mRoot->copyToDense(mDense->bbox(), *mDense);
402 } else {
403 tbb::parallel_for(mDense->bbox(), *this);
404 }
405 }
406
407 /// @brief Public method called by tbb::parallel_for
408 void operator()(const CoordBBox& bbox) const
409 {
410 mRoot->copyToDense(bbox, *mDense);
411 }
412
413private:
414 const typename TreeT::RootNodeType* mRoot;
415 DenseT* mDense;
416};// CopyToDense
417
418
419// Convenient wrapper function for the CopyToDense class
420template<typename DenseT, typename GridOrTreeT>
421void
422copyToDense(const GridOrTreeT& sparse, DenseT& dense, bool serial)
423{
424 using Adapter = TreeAdapter<GridOrTreeT>;
425 using TreeT = typename Adapter::TreeType;
426
427 CopyToDense<TreeT, DenseT> op(Adapter::constTree(sparse), dense);
428 op.copy(serial);
429}
430
431
432////////////////////////////////////////
433
434
435/// @brief Copy the values from a dense grid into an OpenVDB tree.
436///
437/// @details Values in the dense grid that are within a tolerance of
438/// the background value are truncated to inactive background voxels or tiles.
439/// This allows the tree to form a sparse representation of the dense grid.
440///
441/// @note Since this class allocates leaf nodes concurrently it is recommended
442/// to use a scalable implementation of @c new like the one provided by TBB,
443/// rather than the mutex-protected standard library @c new.
444template<typename _TreeT, typename _DenseT = Dense<typename _TreeT::ValueType> >
446{
447public:
448 using DenseT = _DenseT;
449 using TreeT = _TreeT;
450 using ValueT = typename TreeT::ValueType;
451 using LeafT = typename TreeT::LeafNodeType;
453
454 CopyFromDense(const DenseT& dense, TreeT& tree, const ValueT& tolerance)
455 : mDense(&dense),
456 mTree(&tree),
457 mBlocks(nullptr),
458 mTolerance(tolerance),
459 mAccessor(tree.empty() ? nullptr : new AccessorT(tree))
460 {
461 }
463 : mDense(other.mDense),
464 mTree(other.mTree),
465 mBlocks(other.mBlocks),
466 mTolerance(other.mTolerance),
467 mAccessor(other.mAccessor.get() == nullptr ? nullptr : new AccessorT(*mTree))
468 {
469 }
470
471 /// @brief Copy values from the dense grid to the sparse tree.
472 void copy(bool serial = false)
473 {
474 mBlocks = new std::vector<Block>();
475 const CoordBBox& bbox = mDense->bbox();
476 // Pre-process: Construct a list of blocks aligned with (potential) leaf nodes
477 for (CoordBBox sub=bbox; sub.min()[0] <= bbox.max()[0]; sub.min()[0] = sub.max()[0] + 1) {
478 for (sub.min()[1] = bbox.min()[1]; sub.min()[1] <= bbox.max()[1];
479 sub.min()[1] = sub.max()[1] + 1)
480 {
481 for (sub.min()[2] = bbox.min()[2]; sub.min()[2] <= bbox.max()[2];
482 sub.min()[2] = sub.max()[2] + 1)
483 {
484 sub.max() = Coord::minComponent(bbox.max(),
485 (sub.min()&(~(LeafT::DIM-1u))).offsetBy(LeafT::DIM-1u));
486 mBlocks->push_back(Block(sub));
487 }
488 }
489 }
490
491 // Multi-threaded process: Convert dense grid into leaf nodes and tiles
492 if (serial) {
493 (*this)(tbb::blocked_range<size_t>(0, mBlocks->size()));
494 } else {
495 tbb::parallel_for(tbb::blocked_range<size_t>(0, mBlocks->size()), *this);
496 }
497
498 // Post-process: Insert leaf nodes and tiles into the tree, and prune the tiles only!
499 tree::ValueAccessor<TreeT> acc(*mTree);
500 for (size_t m=0, size = mBlocks->size(); m<size; ++m) {
501 Block& block = (*mBlocks)[m];
502 if (block.leaf) {
503 acc.addLeaf(block.leaf);
504 } else if (block.tile.second) {//only background tiles are inactive
505 acc.addTile(1, block.bbox.min(), block.tile.first, true);//leaf tile
506 }
507 }
508 delete mBlocks;
509 mBlocks = nullptr;
510
511 tools::pruneTiles(*mTree, mTolerance);//multi-threaded
512 }
513
514 /// @brief Public method called by tbb::parallel_for
515 /// @warning Never call this method directly!
516 void operator()(const tbb::blocked_range<size_t> &r) const
517 {
518 OPENVDB_ASSERT(mBlocks);
519 LeafT* leaf = new LeafT();
520
521 for (size_t m=r.begin(), n=0, end = r.end(); m != end; ++m, ++n) {
522
523 Block& block = (*mBlocks)[m];
524 const CoordBBox &bbox = block.bbox;
525
526 if (mAccessor.get() == nullptr) {//i.e. empty target tree
527 leaf->fill(mTree->background(), false);
528 } else {//account for existing leaf nodes in the target tree
529 if (const LeafT* target = mAccessor->probeConstLeaf(bbox.min())) {
530 (*leaf) = (*target);
531 } else {
532 ValueT value = zeroVal<ValueT>();
533 bool state = mAccessor->probeValue(bbox.min(), value);
534 leaf->fill(value, state);
535 }
536 }
537
538 leaf->copyFromDense(bbox, *mDense, mTree->background(), mTolerance);
539
540 if (!leaf->isConstant(block.tile.first, block.tile.second, mTolerance)) {
541 leaf->setOrigin(bbox.min() & (~(LeafT::DIM - 1)));
542 block.leaf = leaf;
543 leaf = new LeafT();
544 }
545 }// loop over blocks
546
547 delete leaf;
548 }
549
550private:
551 struct Block {
552 CoordBBox bbox;
553 LeafT* leaf;
554 std::pair<ValueT, bool> tile;
555 Block(const CoordBBox& b) : bbox(b), leaf(nullptr) {}
556 };
557
558 const DenseT* mDense;
559 TreeT* mTree;
560 std::vector<Block>* mBlocks;
561 ValueT mTolerance;
562 std::unique_ptr<AccessorT> mAccessor;
563};// CopyFromDense
564
565
566// Convenient wrapper function for the CopyFromDense class
567template<typename DenseT, typename GridOrTreeT>
568void
569copyFromDense(const DenseT& dense, GridOrTreeT& sparse,
570 const typename GridOrTreeT::ValueType& tolerance, bool serial)
571{
572 using Adapter = TreeAdapter<GridOrTreeT>;
573 using TreeT = typename Adapter::TreeType;
574
575 CopyFromDense<TreeT, DenseT> op(dense, Adapter::tree(sparse), tolerance);
576 op.copy(serial);
577}
578
579} // namespace tools
580} // namespace OPENVDB_VERSION_NAME
581} // namespace openvdb
582
583#endif // OPENVDB_TOOLS_DENSE_HAS_BEEN_INCLUDED
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Utility routines to output nicely-formatted numeric values.
Defined various multi-threaded utility functions for trees.
ValueAccessors are designed to help accelerate accesses into the OpenVDB Tree structures by storing c...
Int32 ValueType
Definition Coord.h:33
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition Coord.h:176
Definition Exceptions.h:65
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
const Coord & min() const
Definition Coord.h:324
const Coord & max() const
Definition Coord.h:325
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition Coord.h:92
static Coord min()
Return the smallest possible coordinate.
Definition Coord.h:44
static Coord max()
Return the largest possible coordinate.
Definition Coord.h:47
Copy the values from a dense grid into an OpenVDB tree.
Definition Dense.h:446
CopyFromDense(const DenseT &dense, TreeT &tree, const ValueT &tolerance)
Definition Dense.h:454
void copy(bool serial=false)
Copy values from the dense grid to the sparse tree.
Definition Dense.h:472
typename TreeT::LeafNodeType LeafT
Definition Dense.h:451
tree::ValueAccessor< TreeT > AccessorT
Definition Dense.h:452
CopyFromDense(const CopyFromDense &other)
Definition Dense.h:462
void operator()(const tbb::blocked_range< size_t > &r) const
Public method called by tbb::parallel_for.
Definition Dense.h:516
typename TreeT::ValueType ValueT
Definition Dense.h:450
_TreeT TreeT
Definition Dense.h:449
_DenseT DenseT
Definition Dense.h:448
Copy an OpenVDB tree into an existing dense grid.
Definition Dense.h:389
void copy(bool serial=false) const
Definition Dense.h:398
CopyToDense(const TreeT &tree, DenseT &dense)
Definition Dense.h:395
void operator()(const CoordBBox &bbox) const
Public method called by tbb::parallel_for.
Definition Dense.h:408
typename TreeT::ValueType ValueT
Definition Dense.h:393
_TreeT TreeT
Definition Dense.h:392
_DenseT DenseT
Definition Dense.h:391
size_t coordToOffset(size_t i, size_t j, size_t k) const
Return the linear offset into this grid's value array given by unsigned coordinates (i,...
Definition Dense.h:136
Coord offsetToLocalCoord(size_t n) const
Return the index coordinate corresponding to the specified linear offset.
Definition Dense.h:142
DenseBase(const CoordBBox &bbox)
Protected constructor so as to prevent direct instantiation.
Definition Dense.h:164
const CoordBBox mBBox
Definition Dense.h:166
size_t zStride() const
Return the stride of the array in the y direction ( = dimX*dimY).
Definition Dense.h:160
static size_t xStride()
Return the stride of the array in the x direction ( = 1).
Definition Dense.h:152
size_t yStride() const
Return the stride of the array in the y direction ( = dimX).
Definition Dense.h:156
size_t coordToOffset(size_t i, size_t j, size_t k) const
Return the linear offset into this grid's value array given by unsigned coordinates (i,...
Definition Dense.h:89
Coord offsetToLocalCoord(size_t n) const
Return the local coordinate corresponding to the specified linear offset.
Definition Dense.h:95
DenseBase(const CoordBBox &bbox)
Protected constructor so as to prevent direct instantiation.
Definition Dense.h:117
const CoordBBox mBBox
Definition Dense.h:119
static size_t zStride()
Return the stride of the array in the z direction ( = 1).
Definition Dense.h:113
size_t yStride() const
Return the stride of the array in the y direction ( = dimZ).
Definition Dense.h:109
size_t xStride() const
Return the stride of the array in the x direction ( = dimY*dimZ).
Definition Dense.h:105
Base class for Dense which is defined below.
Definition Dense.h:74
Dense(const Coord &dim, const Coord &min=Coord(0))
Construct a dense grid with a given origin and dimensions.
Definition Dense.h:233
const ValueT & getValue(const Coord &xyz) const
Return a const reference to the value of the voxel at the given signed coordinates.
Definition Dense.h:301
DenseBase< ValueT, Layout > BaseT
Definition Dense.h:187
Dense(const CoordBBox &bbox, const ValueT &value)
Construct a dense grid with a given range of coordinates and initial value.
Definition Dense.h:204
SharedPtr< Dense > Ptr
Definition Dense.h:188
ValueT & getValue(const Coord &xyz)
Return a non-const reference to the value of the voxel at the given signed coordinates.
Definition Dense.h:309
const Coord & origin() const
Return the grid's origin in index coordinates.
Definition Dense.h:255
Index64 valueCount() const
Return the number of voxels contained in this grid.
Definition Dense.h:258
Dense(const CoordBBox &bbox)
Construct a dense grid with a given range of coordinates.
Definition Dense.h:196
Dense(const CoordBBox &bbox, ValueT *data)
Construct a dense grid that wraps an external array.
Definition Dense.h:219
const ValueT & getValue(size_t offset) const
Return a const reference to the value of the voxel at the given array offset.
Definition Dense.h:264
ValueT ValueType
Definition Dense.h:186
void fill(const ValueT &value)
Definition Dense.h:315
void setValue(size_t offset, const ValueT &value)
Set the value of the voxel at the given array offset.
Definition Dense.h:261
void setValue(const Coord &xyz, const ValueT &value)
Set the value of the voxel at the given signed coordinates.
Definition Dense.h:294
const ValueT * data() const
Return a raw pointer to this grid's value array.
Definition Dense.h:248
ValueT & getValue(size_t i, size_t j, size_t k)
Return a non-const reference to the value of the voxel at unsigned index coordinates (i,...
Definition Dense.h:287
static MemoryLayout memoryLayout()
Return the memory layout for this grid (see above for definitions).
Definition Dense.h:240
void setValue(size_t i, size_t j, size_t k, const ValueT &value)
Set the value of the voxel at unsigned index coordinates (i, j, k).
Definition Dense.h:271
const ValueT & getValue(size_t i, size_t j, size_t k) const
Return a const reference to the value of the voxel at unsigned index coordinates (i,...
Definition Dense.h:279
SharedPtr< const Dense > ConstPtr
Definition Dense.h:189
ValueT & getValue(size_t offset)
Return a non-const reference to the value of the voxel at the given array offset.
Definition Dense.h:267
const CoordBBox & bbox() const
Definition Dense.h:252
Index64 memUsage() const
Return the memory footprint of this Dense grid in bytes.
Definition Dense.h:343
void print(const std::string &name="", std::ostream &os=std::cout) const
Output a human-readable description of this grid to the specified stream.
Definition Dense.h:350
Coord offsetToCoord(size_t n) const
Return the global coordinate corresponding to the specified linear offset.
Definition Dense.h:337
size_t coordToOffset(const Coord &xyz) const
Definition Dense.h:328
void addLeaf(LeafNodeT *leaf)
Add the specified leaf to this tree, possibly creating a child branch in the process....
Definition ValueAccessor.h:729
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Add a tile at the specified tree level that contains the coordinate xyz, possibly deleting existing n...
Definition ValueAccessor.h:754
OutGridT XformOp & op
Definition ValueTransformer.h:140
void copyFromDense(const DenseT &dense, GridOrTreeT &sparse, const typename GridOrTreeT::ValueType &tolerance, bool serial=false)
Populate a sparse grid with the values of all of the voxels of a dense grid.
Definition Dense.h:569
MemoryLayout
Definition Dense.h:69
@ LayoutXYZ
Definition Dense.h:69
@ LayoutZYX
Definition Dense.h:69
void pruneTiles(TreeT &tree, typename TreeT::ValueType tolerance=zeroVal< typename TreeT::ValueType >(), bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing with tiles any non-leaf nodes whose values are all...
Definition Prune.h:345
void copyToDense(const GridOrTreeT &sparse, DenseT &dense, bool serial=false)
Populate a dense grid with the values of voxels from a sparse grid, where the sparse grid intersects ...
Definition Dense.h:422
Definition PointDataGrid.h:170
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
FormattedInt< IntT > formattedInt(IntT n)
Definition Formats.h:118
OPENVDB_API int printBytes(std::ostream &os, uint64_t bytes, const std::string &head="", const std::string &tail="\n", bool exact=false, int width=8, int precision=3)
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:70
uint64_t Index64
Definition Types.h:53
std::shared_ptr< T > SharedPtr
Definition Types.h:114
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition Grid.h:1060
#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:218