OpenVDB: Dense.h Source File

OpenVDB 6.0.0

Dense.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2018 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30
35
36 #ifndef OPENVDB_TOOLS_DENSE_HAS_BEEN_INCLUDED
37 #define OPENVDB_TOOLS_DENSE_HAS_BEEN_INCLUDED
38
39 #include <openvdb/Types.h>
40 #include <openvdb/Grid.h>
41 #include <openvdb/tree/ValueAccessor.h>
42 #include <openvdb/Exceptions.h>
43 #include <openvdb/util/Formats.h>
44 #include "Prune.h"
45 #include <tbb/parallel_for.h>
46 #include <iostream>
47 #include <memory>
48 #include <string>
49 #include <utility> // for std::pair
50 #include <vector>
51
52 namespace openvdb {
53 OPENVDB_USE_VERSION_NAMESPACE
54 namespace OPENVDB_VERSION_NAME {
55 namespace tools {
56
62 template<typename DenseT, typename GridOrTreeT>
63 void
64 copyToDense(
65 const GridOrTreeT& sparse,
66 DenseT& dense,
67 bool serial = false);
68
69
76 template<typename DenseT, typename GridOrTreeT>
77 void
78 copyFromDense(
79 const DenseT& dense,
80 GridOrTreeT& sparse,
81 const typename GridOrTreeT::ValueType& tolerance,
82 bool serial = false);
83
84
86
95 enum MemoryLayout { LayoutXYZ, LayoutZYX };
96
100 template<typename ValueT, MemoryLayout Layout> class DenseBase;
101
105 template<typename ValueT>
106 class DenseBase<ValueT, LayoutZYX>
107 {
108 public:
115 inline size_t coordToOffset(size_t i, size_t j, size_t k) const { return i*mX + j*mY + k; }
116
121 inline Coord offsetToLocalCoord(size_t n) const
122 {
123 const size_t x = n / mX;
124 n -= mX*x;
125 const size_t y = n / mY;
126 return Coord(Coord::ValueType(x), Coord::ValueType(y), Coord::ValueType(n - mY*y));
127 }
128
131 inline size_t xStride() const { return mX; }
132
135 inline size_t yStride() const { return mY; }
136
139 static size_t zStride() { return 1; }
140
141 protected:
143 DenseBase(const CoordBBox& bbox) : mBBox(bbox), mY(bbox.dim()[2]), mX(mY*bbox.dim()[1]) {}
144
145 const CoordBBox mBBox;//signed coordinates of the domain represented by the grid
146 const size_t mY, mX;//strides in the y and x direction
147 };// end of DenseBase<ValueT, LayoutZYX>
148
152 template<typename ValueT>
153 class DenseBase<ValueT, LayoutXYZ>
154 {
155 public:
162 inline size_t coordToOffset(size_t i, size_t j, size_t k) const { return i + j*mY + k*mZ; }
163
168 inline Coord offsetToLocalCoord(size_t n) const
169 {
170 const size_t z = n / mZ;
171 n -= mZ*z;
172 const size_t y = n / mY;
173 return Coord(Coord::ValueType(n - mY*y), Coord::ValueType(y), Coord::ValueType(z));
174 }
175
178 static size_t xStride() { return 1; }
179
182 inline size_t yStride() const { return mY; }
183
186 inline size_t zStride() const { return mZ; }
187
188 protected:
190 DenseBase(const CoordBBox& bbox) : mBBox(bbox), mY(bbox.dim()[0]), mZ(mY*bbox.dim()[1]) {}
191
192 const CoordBBox mBBox;//signed coordinates of the domain represented by the grid
193 const size_t mY, mZ;//strides in the y and z direction
194 };// end of DenseBase<ValueT, LayoutXYZ>
195
208 template<typename ValueT, MemoryLayout Layout = LayoutZYX>
209 class Dense : public DenseBase<ValueT, Layout>
210 {
211 public:
212 using ValueType = ValueT;
213 using BaseT = DenseBase<ValueT, Layout>;
214 using Ptr = SharedPtr<Dense>;
215 using ConstPtr = SharedPtr<const Dense>;
216
222 Dense(const CoordBBox& bbox) : BaseT(bbox) { this->init(); }
223
230 Dense(const CoordBBox& bbox, const ValueT& value) : BaseT(bbox)
231 {
232 this->init();
233 this->fill(value);
234 }
235
245 Dense(const CoordBBox& bbox, ValueT* data) : BaseT(bbox), mData(data)
246 {
247 if (BaseT::mBBox.empty()) {
248 OPENVDB_THROW(ValueError, "can't construct a dense grid with an empty bounding box");
249 }
250 }
251
259 Dense(const Coord& dim, const Coord& min = Coord(0))
260 : BaseT(CoordBBox(min, min+dim.offsetBy(-1)))
261 {
262 this->init();
263 }
264
266 static MemoryLayout memoryLayout() { return Layout; }
267
270 inline ValueT* data() { return mData; }
271
274 inline const ValueT* data() const { return mData; }
275
278 inline const CoordBBox& bbox() const { return BaseT::mBBox; }
279
281 inline const Coord& origin() const { return BaseT::mBBox.min(); }
282
284 inline Index64 valueCount() const { return BaseT::mBBox.volume(); }
285
287 inline void setValue(size_t offset, const ValueT& value) { mData[offset] = value; }
288
290 const ValueT& getValue(size_t offset) const { return mData[offset]; }
291
293 ValueT& getValue(size_t offset) { return mData[offset]; }
294
297 inline void setValue(size_t i, size_t j, size_t k, const ValueT& value)
298 {
299 mData[BaseT::coordToOffset(i,j,k)] = value;
300 }
301
305 inline const ValueT& getValue(size_t i, size_t j, size_t k) const
306 {
307 return mData[BaseT::coordToOffset(i,j,k)];
308 }
309
313 inline ValueT& getValue(size_t i, size_t j, size_t k)
314 {
315 return mData[BaseT::coordToOffset(i,j,k)];
316 }
317
320 inline void setValue(const Coord& xyz, const ValueT& value)
321 {
322 mData[this->coordToOffset(xyz)] = value;
323 }
324
327 inline const ValueT& getValue(const Coord& xyz) const
328 {
329 return mData[this->coordToOffset(xyz)];
330 }
331
335 inline ValueT& getValue(const Coord& xyz)
336 {
337 return mData[this->coordToOffset(xyz)];
338 }
339
341 inline void fill(const ValueT& value)
342 {
343 size_t size = this->valueCount();
344 ValueT* a = mData;
345 while(size--) *a++ = value;
346 }
347
354 inline size_t coordToOffset(const Coord& xyz) const
355 {
356 assert(BaseT::mBBox.isInside(xyz));
357 return BaseT::coordToOffset(size_t(xyz[0]-BaseT::mBBox.min()[0]),
358 size_t(xyz[1]-BaseT::mBBox.min()[1]),
359 size_t(xyz[2]-BaseT::mBBox.min()[2]));
360 }
361
363 inline Coord offsetToCoord(size_t n) const
364 {
365 return this->offsetToLocalCoord(n) + BaseT::mBBox.min();
366 }
367
369 inline Index64 memUsage() const
370 {
371 return sizeof(*this) + BaseT::mBBox.volume() * sizeof(ValueType);
372 }
373
376 void print(const std::string& name = "", std::ostream& os = std::cout) const
377 {
378 const Coord dim = BaseT::mBBox.dim();
379 os << "Dense Grid";
380 if (!name.empty()) os << " \"" << name << "\"";
381 util::printBytes(os, this->memUsage(), ":\n Memory footprint: ");
382 os << " Dimensions of grid : " << dim[0] << " x " << dim[1] << " x " << dim[2] << "\n";
383 os << " Number of voxels: " << util::formattedInt(this->valueCount()) << "\n";
384 os << " Bounding box of voxels: " << BaseT::mBBox << "\n";
385 os << " Memory layout: " << (Layout == LayoutZYX ? "ZYX (" : "XYZ (dis")
386 << "similar to VDB)\n";
387 }
388
389 private:
391 void init()
392 {
393 if (BaseT::mBBox.empty()) {
394 OPENVDB_THROW(ValueError, "can't construct a dense grid with an empty bounding box");
395 }
396 mArray.reset(new ValueT[BaseT::mBBox.volume()]);
397 mData = mArray.get();
398 }
399
400 std::unique_ptr<ValueT[]> mArray;
401 ValueT* mData;//raw c-style pointer to values
402 };// end of Dense
403
405
406
413 template<typename _TreeT, typename _DenseT = Dense<typename _TreeT::ValueType> >
414 class CopyToDense
415 {
416 public:
417 using DenseT = _DenseT;
418 using TreeT = _TreeT;
419 using ValueT = typename TreeT::ValueType;
420
421 CopyToDense(const TreeT& tree, DenseT& dense)
422 : mRoot(&(tree.root())), mDense(&dense) {}
423
424 void copy(bool serial = false) const
425 {
426 if (serial) {
427 mRoot->copyToDense(mDense->bbox(), *mDense);
428 } else {
429 tbb::parallel_for(mDense->bbox(), *this);
430 }
431 }
432
434 void operator()(const CoordBBox& bbox) const
435 {
436 mRoot->copyToDense(bbox, *mDense);
437 }
438
439 private:
440 const typename TreeT::RootNodeType* mRoot;
441 DenseT* mDense;
442 };// CopyToDense
443
444
445 // Convenient wrapper function for the CopyToDense class
446 template<typename DenseT, typename GridOrTreeT>
447 void
448 copyToDense(const GridOrTreeT& sparse, DenseT& dense, bool serial)
449 {
450 using Adapter = TreeAdapter<GridOrTreeT>;
451 using TreeT = typename Adapter::TreeType;
452
453 CopyToDense<TreeT, DenseT> op(Adapter::constTree(sparse), dense);
454 op.copy(serial);
455 }
456
457
459
460
470 template<typename _TreeT, typename _DenseT = Dense<typename _TreeT::ValueType> >
471 class CopyFromDense
472 {
473 public:
474 using DenseT = _DenseT;
475 using TreeT = _TreeT;
476 using ValueT = typename TreeT::ValueType;
477 using LeafT = typename TreeT::LeafNodeType;
478 using AccessorT = tree::ValueAccessor<TreeT>;
479
480 CopyFromDense(const DenseT& dense, TreeT& tree, const ValueT& tolerance)
481 : mDense(&dense),
482 mTree(&tree),
483 mBlocks(nullptr),
484 mTolerance(tolerance),
485 mAccessor(tree.empty() ? nullptr : new AccessorT(tree))
486 {
487 }
488 CopyFromDense(const CopyFromDense& other)
489 : mDense(other.mDense),
490 mTree(other.mTree),
491 mBlocks(other.mBlocks),
492 mTolerance(other.mTolerance),
493 mAccessor(other.mAccessor.get() == nullptr ? nullptr : new AccessorT(*mTree))
494 {
495 }
496
498 void copy(bool serial = false)
499 {
500 mBlocks = new std::vector<Block>();
501 const CoordBBox& bbox = mDense->bbox();
502 // Pre-process: Construct a list of blocks aligned with (potential) leaf nodes
503 for (CoordBBox sub=bbox; sub.min()[0] <= bbox.max()[0]; sub.min()[0] = sub.max()[0] + 1) {
504 for (sub.min()[1] = bbox.min()[1]; sub.min()[1] <= bbox.max()[1];
505 sub.min()[1] = sub.max()[1] + 1)
506 {
507 for (sub.min()[2] = bbox.min()[2]; sub.min()[2] <= bbox.max()[2];
508 sub.min()[2] = sub.max()[2] + 1)
509 {
510 sub.max() = Coord::minComponent(bbox.max(),
511 (sub.min()&(~(LeafT::DIM-1u))).offsetBy(LeafT::DIM-1u));
512 mBlocks->push_back(Block(sub));
513 }
514 }
515 }
516
517 // Multi-threaded process: Convert dense grid into leaf nodes and tiles
518 if (serial) {
519 (*this)(tbb::blocked_range<size_t>(0, mBlocks->size()));
520 } else {
521 tbb::parallel_for(tbb::blocked_range<size_t>(0, mBlocks->size()), *this);
522 }
523
524 // Post-process: Insert leaf nodes and tiles into the tree, and prune the tiles only!
525 tree::ValueAccessor<TreeT> acc(*mTree);
526 for (size_t m=0, size = mBlocks->size(); m<size; ++m) {
527 Block& block = (*mBlocks)[m];
528 if (block.leaf) {
529 acc.addLeaf(block.leaf);
530 } else if (block.tile.second) {//only background tiles are inactive
531 acc.addTile(1, block.bbox.min(), block.tile.first, true);//leaf tile
532 }
533 }
534 delete mBlocks;
535 mBlocks = nullptr;
536
537 tools::pruneTiles(*mTree, mTolerance);//multi-threaded
538 }
539
542 void operator()(const tbb::blocked_range<size_t> &r) const
543 {
544 assert(mBlocks);
545 LeafT* leaf = new LeafT();
546
547 for (size_t m=r.begin(), n=0, end = r.end(); m != end; ++m, ++n) {
548
549 Block& block = (*mBlocks)[m];
550 const CoordBBox &bbox = block.bbox;
551
552 if (mAccessor.get() == nullptr) {//i.e. empty target tree
553 leaf->fill(mTree->background(), false);
554 } else {//account for existing leaf nodes in the target tree
555 if (const LeafT* target = mAccessor->probeConstLeaf(bbox.min())) {
556 (*leaf) = (*target);
557 } else {
558 ValueT value = zeroVal<ValueT>();
559 bool state = mAccessor->probeValue(bbox.min(), value);
560 leaf->fill(value, state);
561 }
562 }
563
564 leaf->copyFromDense(bbox, *mDense, mTree->background(), mTolerance);
565
566 if (!leaf->isConstant(block.tile.first, block.tile.second, mTolerance)) {
567 leaf->setOrigin(bbox.min() & (~(LeafT::DIM - 1)));
568 block.leaf = leaf;
569 leaf = new LeafT();
570 }
571 }// loop over blocks
572
573 delete leaf;
574 }
575
576 private:
577 struct Block {
578 CoordBBox bbox;
579 LeafT* leaf;
580 std::pair<ValueT, bool> tile;
581 Block(const CoordBBox& b) : bbox(b), leaf(nullptr) {}
582 };
583
584 const DenseT* mDense;
585 TreeT* mTree;
586 std::vector<Block>* mBlocks;
587 ValueT mTolerance;
588 std::unique_ptr<AccessorT> mAccessor;
589 };// CopyFromDense
590
591
592 // Convenient wrapper function for the CopyFromDense class
593 template<typename DenseT, typename GridOrTreeT>
594 void
595 copyFromDense(const DenseT& dense, GridOrTreeT& sparse,
596 const typename GridOrTreeT::ValueType& tolerance, bool serial)
597 {
598 using Adapter = TreeAdapter<GridOrTreeT>;
599 using TreeT = typename Adapter::TreeType;
600
601 CopyFromDense<TreeT, DenseT> op(dense, Adapter::tree(sparse), tolerance);
602 op.copy(serial);
603 }
604
605 } // namespace tools
606 } // namespace OPENVDB_VERSION_NAME
607 } // namespace openvdb
608
609 #endif // OPENVDB_TOOLS_DENSE_HAS_BEEN_INCLUDED
610
611 // Copyright (c) 2012-2018 DreamWorks Animation LLC
612 // All rights reserved. This software is distributed under the
613 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v6_0::TreeAdapter
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:944
openvdb::v6_0::tools::MemoryLayout
MemoryLayout
Definition: Dense.h:95
openvdb::v6_0::tools::Dense::coordToOffset
size_t coordToOffset(const Coord &xyz) const
Return the linear offset into this grid's value array given by the specified signed coordinates,...
Definition: Dense.h:354
openvdb::v6_0::tools::Dense::bbox
const CoordBBox & bbox() const
Return the bounding box of the signed index domain of this grid.
Definition: Dense.h:278
Types.h
openvdb::v6_0::tools::Dense::getValue
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:313
openvdb::v6_0::util::formattedInt
FormattedInt< IntT > formattedInt(IntT n)
Definition: Formats.h:130
openvdb::v6_0::tools::CopyFromDense::LeafT
typename TreeT::LeafNodeType LeafT
Definition: Dense.h:477
Formats.h
Utility routines to output nicely-formatted numeric values.
openvdb::v6_0::tools::Dense::getValue
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:290
openvdb::v6_0::Index64
uint64_t Index64
Definition: Types.h:60
openvdb::v6_0::tools::CopyFromDense::DenseT
_DenseT DenseT
Definition: Dense.h:474
openvdb::v6_0::tools::copyFromDense
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:595
openvdb::v6_0::tools::CopyToDense
Copy an OpenVDB tree into an existing dense grid.
Definition: Dense.h:414
openvdb::v6_0::tools::DenseBase< ValueT, LayoutZYX >::xStride
size_t xStride() const
Return the stride of the array in the x direction ( = dimY*dimZ).
Definition: Dense.h:131
openvdb::v6_0::tools::CopyToDense::TreeT
_TreeT TreeT
Definition: Dense.h:418
openvdb::v6_0::tools::Dense::fill
void fill(const ValueT &value)
Fill this grid with a constant value.
Definition: Dense.h:341
openvdb::v6_0::tools::DenseBase< ValueT, LayoutZYX >::zStride
static size_t zStride()
Return the stride of the array in the z direction ( = 1).
Definition: Dense.h:139
openvdb::v6_0::tools::CopyFromDense::copy
void copy(bool serial=false)
Copy values from the dense grid to the sparse tree.
Definition: Dense.h:498
openvdb::v6_0::tools::Dense::Dense
Dense(const Coord &dim, const Coord &min=Coord(0))
Construct a dense grid with a given origin and dimensions.
Definition: Dense.h:259
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
openvdb::v6_0::tools::DenseBase< ValueT, LayoutXYZ >::offsetToLocalCoord
Coord offsetToLocalCoord(size_t n) const
Return the index coordinate corresponding to the specified linear offset.
Definition: Dense.h:168
openvdb::v6_0::tools::copyToDense
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:448
openvdb::v6_0::math::CoordBBox::max
const Coord & max() const
Definition: Coord.h:338
openvdb::v6_0::tools::CopyToDense::ValueT
typename TreeT::ValueType ValueT
Definition: Dense.h:419
openvdb::v6_0::tools::DenseBase< ValueT, LayoutXYZ >::coordToOffset
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:162
openvdb::v6_0::tools::CopyFromDense::CopyFromDense
CopyFromDense(const DenseT &dense, TreeT &tree, const ValueT &tolerance)
Definition: Dense.h:480
openvdb::v6_0::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
openvdb::v6_0::tools::CopyFromDense::operator()
void operator()(const tbb::blocked_range< size_t > &r) const
Public method called by tbb::parallel_for.
Definition: Dense.h:542
openvdb::v6_0::tools::DenseBase< ValueT, LayoutZYX >::yStride
size_t yStride() const
Return the stride of the array in the y direction ( = dimZ).
Definition: Dense.h:135
openvdb::v6_0::tools::Dense::getValue
ValueT & getValue(const Coord &xyz)
Return a non-const reference to the value of the voxel at the given signed coordinates.
Definition: Dense.h:335
Prune.h
Defined various multi-threaded utility functions for trees.
openvdb::v6_0::tools::Dense::setValue
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:297
openvdb::v6_0::tools::DenseBase
Base class for Dense which is defined below.
Definition: Dense.h:100
openvdb::v6_0::tools::Dense::ValueType
ValueT ValueType
Definition: Dense.h:212
openvdb::v6_0::tools::DenseBase< ValueT, LayoutXYZ >::mBBox
const CoordBBox mBBox
Definition: Dense.h:192
openvdb::v6_0::tools::CopyFromDense::TreeT
_TreeT TreeT
Definition: Dense.h:475
openvdb::v6_0::tools::CopyToDense::CopyToDense
CopyToDense(const TreeT &tree, DenseT &dense)
Definition: Dense.h:421
openvdb::v6_0::tools::CopyToDense::DenseT
_DenseT DenseT
Definition: Dense.h:417
openvdb::v6_0::tools::DenseBase< ValueT, LayoutZYX >::mBBox
const CoordBBox mBBox
Definition: Dense.h:145
openvdb::v6_0::tools::Dense::data
const ValueT * data() const
Return a raw pointer to this grid's value array.
Definition: Dense.h:274
openvdb::v6_0::tools::DenseBase< ValueT, LayoutZYX >::mY
const size_t mY
Definition: Dense.h:146
openvdb::v6_0::tools::pruneTiles
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:371
openvdb::v6_0::tools::CopyToDense::copy
void copy(bool serial=false) const
Definition: Dense.h:424
Exceptions.h
openvdb::v6_0::tools::Dense::setValue
void setValue(size_t offset, const ValueT &value)
Set the value of the voxel at the given array offset.
Definition: Dense.h:287
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
openvdb::v6_0::tools::DenseBase< ValueT, LayoutXYZ >::yStride
size_t yStride() const
Return the stride of the array in the y direction ( = dimX).
Definition: Dense.h:182
openvdb::v6_0::tools::Dense
Dense is a simple dense grid API used by the CopyToDense and CopyFromDense classes defined below.
Definition: Dense.h:209
openvdb::v6_0::util::printBytes
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)
openvdb::v6_0::math::CoordBBox::min
const Coord & min() const
Definition: Coord.h:337
openvdb::v6_0::tools::Dense::valueCount
Index64 valueCount() const
Return the number of voxels contained in this grid.
Definition: Dense.h:284
openvdb
Definition: Exceptions.h:40
openvdb::v6_0::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:264
openvdb::v6_0::tree::ValueAccessor::addTile
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Add a tile at the specified tree level that contains voxel (x, y, z), possibly deleting existing node...
Definition: ValueAccessor.h:375
openvdb::v6_0::tools::Dense::data
ValueT * data()
Return a raw pointer to this grid's value array.
Definition: Dense.h:270
openvdb::v6_0::tools::Dense::print
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:376
openvdb::v6_0::tools::LayoutZYX
Definition: Dense.h:95
openvdb::v6_0::tools::Dense::Dense
Dense(const CoordBBox &bbox, const ValueT &value)
Construct a dense grid with a given range of coordinates and initial value.
Definition: Dense.h:230
openvdb::v6_0::math::Coord::ValueType
Int32 ValueType
Definition: Coord.h:59
openvdb::v6_0::tools::DenseBase< ValueT, LayoutXYZ >::mZ
const size_t mZ
Definition: Dense.h:193
openvdb::v6_0::tools::Dense::getValue
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:327
openvdb::v6_0::tools::DenseBase< ValueT, LayoutZYX >::coordToOffset
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:115
openvdb::v6_0::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129
openvdb::v6_0::tools::Dense::memUsage
Index64 memUsage() const
Return the memory footprint of this Dense grid in bytes.
Definition: Dense.h:369
openvdb::v6_0::tree::ValueAccessor< TreeT >
ValueAccessor.h
openvdb::v6_0::tools::Dense::origin
const Coord & origin() const
Return the grid's origin in index coordinates.
Definition: Dense.h:281
openvdb::v6_0::tools::Dense::offsetToCoord
Coord offsetToCoord(size_t n) const
Return the global coordinate corresponding to the specified linear offset.
Definition: Dense.h:363
openvdb::v6_0::math::Coord::min
static Coord min()
Return the smallest possible coordinate.
Definition: Coord.h:70
openvdb::v6_0::SharedPtr
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
openvdb::v6_0::tools::CopyFromDense
Copy the values from a dense grid into an OpenVDB tree.
Definition: Dense.h:471
openvdb::v6_0::tools::DenseBase< ValueT, LayoutXYZ >::DenseBase
DenseBase(const CoordBBox &bbox)
Protected constructor so as to prevent direct instantiation.
Definition: Dense.h:190
openvdb::v6_0::tools::DenseBase< ValueT, LayoutXYZ >::zStride
size_t zStride() const
Return the stride of the array in the y direction ( = dimX*dimY).
Definition: Dense.h:186
Grid.h
openvdb::v6_0::math::Coord::max
static Coord max()
Return the largest possible coordinate.
Definition: Coord.h:73
openvdb::v6_0::tools::Dense::Ptr
SharedPtr< Dense > Ptr
Definition: Dense.h:214
openvdb::v6_0::tools::Dense::Dense
Dense(const CoordBBox &bbox)
Construct a dense grid with a given range of coordinates.
Definition: Dense.h:222
openvdb::v6_0::tools::DenseBase< ValueT, LayoutZYX >::DenseBase
DenseBase(const CoordBBox &bbox)
Protected constructor so as to prevent direct instantiation.
Definition: Dense.h:143
openvdb::v6_0::ValueError
Definition: Exceptions.h:92
openvdb::v6_0::tools::LayoutXYZ
Definition: Dense.h:95
openvdb::v6_0::tree::ValueAccessor::addLeaf
void addLeaf(LeafNodeT *leaf)
Add the specified leaf to this tree, possibly creating a child branch in the process....
Definition: ValueAccessor.h:367
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
openvdb::v6_0::tools::Dense::setValue
void setValue(const Coord &xyz, const ValueT &value)
Set the value of the voxel at the given signed coordinates.
Definition: Dense.h:320
openvdb::v6_0::tools::DenseBase< ValueT, LayoutXYZ >::xStride
static size_t xStride()
Return the stride of the array in the x direction ( = 1).
Definition: Dense.h:178
openvdb::v6_0::math::Coord::minComponent
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition: Coord.h:202
openvdb::v6_0::tools::Dense::getValue
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:305
openvdb::v6_0::tools::Dense::getValue
ValueT & getValue(size_t offset)
Return a non-const reference to the value of the voxel at the given array offset.
Definition: Dense.h:293
openvdb::v6_0::tools::Dense::memoryLayout
static MemoryLayout memoryLayout()
Return the memory layout for this grid (see above for definitions).
Definition: Dense.h:266
openvdb::v6_0::tools::CopyToDense::operator()
void operator()(const CoordBBox &bbox) const
Public method called by tbb::parallel_for.
Definition: Dense.h:434
openvdb::v6_0::tools::DenseBase< ValueT, LayoutZYX >::offsetToLocalCoord
Coord offsetToLocalCoord(size_t n) const
Return the local coordinate corresponding to the specified linear offset.
Definition: Dense.h:121
openvdb::v6_0::tools::CopyFromDense::CopyFromDense
CopyFromDense(const CopyFromDense &other)
Definition: Dense.h:488
openvdb::v6_0::tools::Dense::ConstPtr
SharedPtr< const Dense > ConstPtr
Definition: Dense.h:215
openvdb::v6_0::tools::Dense::Dense
Dense(const CoordBBox &bbox, ValueT *data)
Construct a dense grid that wraps an external array.
Definition: Dense.h:245
openvdb::v6_0::tools::CopyFromDense::ValueT
typename TreeT::ValueType ValueT
Definition: Dense.h:476