OpenVDB: Dense.h Source File

OpenVDB 4.0.2

Dense.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2017 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 <boost/scoped_array.hpp>
46 #include <tbb/parallel_for.h>
47 #include <memory>
48
49 namespace openvdb {
50 OPENVDB_USE_VERSION_NAMESPACE
51 namespace OPENVDB_VERSION_NAME {
52 namespace tools {
53
59 template<typename DenseT, typename GridOrTreeT>
60 void
61 copyToDense(
62 const GridOrTreeT& sparse,
63 DenseT& dense,
64 bool serial = false);
65
66
73 template<typename DenseT, typename GridOrTreeT>
74 void
75 copyFromDense(
76 const DenseT& dense,
77 GridOrTreeT& sparse,
78 const typename GridOrTreeT::ValueType& tolerance,
79 bool serial = false);
80
81
83
92 enum MemoryLayout { LayoutXYZ, LayoutZYX };
93
97 template<typename ValueT, MemoryLayout Layout> class DenseBase;
98
102 template<typename ValueT>
103 class DenseBase<ValueT, LayoutZYX>
104 {
105 public:
112 inline size_t coordToOffset(size_t i, size_t j, size_t k) const { return i*mX + j*mY + k; }
113
118 inline Coord offsetToLocalCoord(size_t n) const
119 {
120 const size_t x = n / mX;
121 n -= mX*x;
122 const size_t y = n / mY;
123 return Coord(Coord::ValueType(x), Coord::ValueType(y), Coord::ValueType(n - mY*y));
124 }
125
128 inline size_t xStride() const { return mX; }
129
132 inline size_t yStride() const { return mY; }
133
136 static size_t zStride() { return 1; }
137
138 protected:
140 DenseBase(const CoordBBox& bbox) : mBBox(bbox), mY(bbox.dim()[2]), mX(mY*bbox.dim()[1]) {}
141
142 const CoordBBox mBBox;//signed coordinates of the domain represented by the grid
143 const size_t mY, mX;//strides in the y and x direction
144 };// end of DenseBase<ValueT, LayoutZYX>
145
149 template<typename ValueT>
150 class DenseBase<ValueT, LayoutXYZ>
151 {
152 public:
159 inline size_t coordToOffset(size_t i, size_t j, size_t k) const { return i + j*mY + k*mZ; }
160
165 inline Coord offsetToLocalCoord(size_t n) const
166 {
167 const size_t z = n / mZ;
168 n -= mZ*z;
169 const size_t y = n / mY;
170 return Coord(Coord::ValueType(n - mY*y), Coord::ValueType(y), Coord::ValueType(z));
171 }
172
175 static size_t xStride() { return 1; }
176
179 inline size_t yStride() const { return mY; }
180
183 inline size_t zStride() const { return mZ; }
184
185 protected:
187 DenseBase(const CoordBBox& bbox) : mBBox(bbox), mY(bbox.dim()[0]), mZ(mY*bbox.dim()[1]) {}
188
189 const CoordBBox mBBox;//signed coordinates of the domain represented by the grid
190 const size_t mY, mZ;//strides in the y and z direction
191 };// end of DenseBase<ValueT, LayoutXYZ>
192
205 template<typename ValueT, MemoryLayout Layout = LayoutZYX>
206 class Dense : public DenseBase<ValueT, Layout>
207 {
208 public:
209 using ValueType = ValueT;
210 using BaseT = DenseBase<ValueT, Layout>;
211 using Ptr = SharedPtr<Dense>;
212 using ConstPtr = SharedPtr<const Dense>;
213
219 Dense(const CoordBBox& bbox) : BaseT(bbox) { this->init(); }
220
227 Dense(const CoordBBox& bbox, const ValueT& value) : BaseT(bbox)
228 {
229 this->init();
230 this->fill(value);
231 }
232
242 Dense(const CoordBBox& bbox, ValueT* data) : BaseT(bbox), mData(data)
243 {
244 if (BaseT::mBBox.empty()) {
245 OPENVDB_THROW(ValueError, "can't construct a dense grid with an empty bounding box");
246 }
247 }
248
256 Dense(const Coord& dim, const Coord& min = Coord(0))
257 : BaseT(CoordBBox(min, min+dim.offsetBy(-1)))
258 {
259 this->init();
260 }
261
263 static MemoryLayout memoryLayout() { return Layout; }
264
267 inline ValueT* data() { return mData; }
268
271 inline const ValueT* data() const { return mData; }
272
275 inline const CoordBBox& bbox() const { return BaseT::mBBox; }
276
278 inline const Coord& origin() const { return BaseT::mBBox.min(); }
279
281 inline Index64 valueCount() const { return BaseT::mBBox.volume(); }
282
284 inline void setValue(size_t offset, const ValueT& value) { mData[offset] = value; }
285
287 const ValueT& getValue(size_t offset) const { return mData[offset]; }
288
290 ValueT& getValue(size_t offset) { return mData[offset]; }
291
294 inline void setValue(size_t i, size_t j, size_t k, const ValueT& value)
295 {
296 mData[BaseT::coordToOffset(i,j,k)] = value;
297 }
298
302 inline const ValueT& getValue(size_t i, size_t j, size_t k) const
303 {
304 return mData[BaseT::coordToOffset(i,j,k)];
305 }
306
310 inline ValueT& getValue(size_t i, size_t j, size_t k)
311 {
312 return mData[BaseT::coordToOffset(i,j,k)];
313 }
314
317 inline void setValue(const Coord& xyz, const ValueT& value)
318 {
319 mData[this->coordToOffset(xyz)] = value;
320 }
321
324 inline const ValueT& getValue(const Coord& xyz) const
325 {
326 return mData[this->coordToOffset(xyz)];
327 }
328
332 inline ValueT& getValue(const Coord& xyz)
333 {
334 return mData[this->coordToOffset(xyz)];
335 }
336
338 inline void fill(const ValueT& value)
339 {
340 size_t size = this->valueCount();
341 ValueT* a = mData;
342 while(size--) *a++ = value;
343 }
344
351 inline size_t coordToOffset(const Coord& xyz) const
352 {
353 assert(BaseT::mBBox.isInside(xyz));
354 return BaseT::coordToOffset(size_t(xyz[0]-BaseT::mBBox.min()[0]),
355 size_t(xyz[1]-BaseT::mBBox.min()[1]),
356 size_t(xyz[2]-BaseT::mBBox.min()[2]));
357 }
358
360 inline Coord offsetToCoord(size_t n) const
361 {
362 return this->offsetToLocalCoord(n) + BaseT::mBBox.min();
363 }
364
366 inline Index64 memUsage() const
367 {
368 return sizeof(*this) + BaseT::mBBox.volume() * sizeof(ValueType);
369 }
370
373 void print(const std::string& name = "", std::ostream& os = std::cout) const
374 {
375 const Coord dim = BaseT::mBBox.dim();
376 os << "Dense Grid";
377 if (!name.empty()) os << " \"" << name << "\"";
378 util::printBytes(os, this->memUsage(), ":\n Memory footprint: ");
379 os << " Dimensions of grid : " << dim[0] << " x " << dim[1] << " x " << dim[2] << "\n";
380 os << " Number of voxels: " << util::formattedInt(this->valueCount()) << "\n";
381 os << " Bounding box of voxels: " << BaseT::mBBox << "\n";
382 os << " Memory layout: " << (Layout == LayoutZYX ? "ZYX (" : "XYZ (dis")
383 << "similar to VDB)\n";
384 }
385
386 private:
388 void init()
389 {
390 if (BaseT::mBBox.empty()) {
391 OPENVDB_THROW(ValueError, "can't construct a dense grid with an empty bounding box");
392 }
393 mArray.reset(new ValueT[BaseT::mBBox.volume()]);
394 mData = mArray.get();
395 }
396
397 boost::scoped_array<ValueT> mArray;
398 ValueT* mData;//raw c-style pointer to values
399 };// end of Dense
400
402
403
410 template<typename _TreeT, typename _DenseT = Dense<typename _TreeT::ValueType> >
411 class CopyToDense
412 {
413 public:
414 using DenseT = _DenseT;
415 using TreeT = _TreeT;
416 using ValueT = typename TreeT::ValueType;
417
418 CopyToDense(const TreeT& tree, DenseT& dense)
419 : mRoot(&(tree.root())), mDense(&dense) {}
420
421 void copy(bool serial = false) const
422 {
423 if (serial) {
424 mRoot->copyToDense(mDense->bbox(), *mDense);
425 } else {
426 tbb::parallel_for(mDense->bbox(), *this);
427 }
428 }
429
431 void operator()(const CoordBBox& bbox) const
432 {
433 mRoot->copyToDense(bbox, *mDense);
434 }
435
436 private:
437 const typename TreeT::RootNodeType* mRoot;
438 DenseT* mDense;
439 };// CopyToDense
440
441
442 // Convenient wrapper function for the CopyToDense class
443 template<typename DenseT, typename GridOrTreeT>
444 void
445 copyToDense(const GridOrTreeT& sparse, DenseT& dense, bool serial)
446 {
447 using Adapter = TreeAdapter<GridOrTreeT>;
448 using TreeT = typename Adapter::TreeType;
449
450 CopyToDense<TreeT, DenseT> op(Adapter::constTree(sparse), dense);
451 op.copy(serial);
452 }
453
454
456
457
467 template<typename _TreeT, typename _DenseT = Dense<typename _TreeT::ValueType> >
468 class CopyFromDense
469 {
470 public:
471 using DenseT = _DenseT;
472 using TreeT = _TreeT;
473 using ValueT = typename TreeT::ValueType;
474 using LeafT = typename TreeT::LeafNodeType;
475 using AccessorT = tree::ValueAccessor<TreeT>;
476
477 CopyFromDense(const DenseT& dense, TreeT& tree, const ValueT& tolerance)
478 : mDense(&dense),
479 mTree(&tree),
480 mBlocks(nullptr),
481 mTolerance(tolerance),
482 mAccessor(tree.empty() ? nullptr : new AccessorT(tree))
483 {
484 }
485 CopyFromDense(const CopyFromDense& other)
486 : mDense(other.mDense),
487 mTree(other.mTree),
488 mBlocks(other.mBlocks),
489 mTolerance(other.mTolerance),
490 mAccessor(other.mAccessor.get() == nullptr ? nullptr : new AccessorT(*mTree))
491 {
492 }
493
495 void copy(bool serial = false)
496 {
497 mBlocks = new std::vector<Block>();
498 const CoordBBox& bbox = mDense->bbox();
499 // Pre-process: Construct a list of blocks aligned with (potential) leaf nodes
500 for (CoordBBox sub=bbox; sub.min()[0] <= bbox.max()[0]; sub.min()[0] = sub.max()[0] + 1) {
501 for (sub.min()[1] = bbox.min()[1]; sub.min()[1] <= bbox.max()[1];
502 sub.min()[1] = sub.max()[1] + 1)
503 {
504 for (sub.min()[2] = bbox.min()[2]; sub.min()[2] <= bbox.max()[2];
505 sub.min()[2] = sub.max()[2] + 1)
506 {
507 sub.max() = Coord::minComponent(bbox.max(),
508 (sub.min()&(~(LeafT::DIM-1u))).offsetBy(LeafT::DIM-1u));
509 mBlocks->push_back(Block(sub));
510 }
511 }
512 }
513
514 // Multi-threaded process: Convert dense grid into leaf nodes and tiles
515 if (serial) {
516 (*this)(tbb::blocked_range<size_t>(0, mBlocks->size()));
517 } else {
518 tbb::parallel_for(tbb::blocked_range<size_t>(0, mBlocks->size()), *this);
519 }
520
521 // Post-process: Insert leaf nodes and tiles into the tree, and prune the tiles only!
522 tree::ValueAccessor<TreeT> acc(*mTree);
523 for (size_t m=0, size = mBlocks->size(); m<size; ++m) {
524 Block& block = (*mBlocks)[m];
525 if (block.leaf) {
526 acc.addLeaf(block.leaf);
527 } else if (block.tile.second) {//only background tiles are inactive
528 acc.addTile(1, block.bbox.min(), block.tile.first, true);//leaf tile
529 }
530 }
531 delete mBlocks;
532 mBlocks = nullptr;
533
534 tools::pruneTiles(*mTree, mTolerance);//multi-threaded
535 }
536
539 void operator()(const tbb::blocked_range<size_t> &r) const
540 {
541 assert(mBlocks);
542 LeafT* leaf = new LeafT();
543
544 for (size_t m=r.begin(), n=0, end = r.end(); m != end; ++m, ++n) {
545
546 Block& block = (*mBlocks)[m];
547 const CoordBBox &bbox = block.bbox;
548
549 if (mAccessor.get() == nullptr) {//i.e. empty target tree
550 leaf->fill(mTree->background(), false);
551 } else {//account for existing leaf nodes in the target tree
552 if (const LeafT* target = mAccessor->probeConstLeaf(bbox.min())) {
553 (*leaf) = (*target);
554 } else {
555 ValueT value = zeroVal<ValueT>();
556 bool state = mAccessor->probeValue(bbox.min(), value);
557 leaf->fill(value, state);
558 }
559 }
560
561 leaf->copyFromDense(bbox, *mDense, mTree->background(), mTolerance);
562
563 if (!leaf->isConstant(block.tile.first, block.tile.second, mTolerance)) {
564 leaf->setOrigin(bbox.min() & (~(LeafT::DIM - 1)));
565 block.leaf = leaf;
566 leaf = new LeafT();
567 }
568 }// loop over blocks
569
570 delete leaf;
571 }
572
573 private:
574 struct Block {
575 CoordBBox bbox;
576 LeafT* leaf;
577 std::pair<ValueT, bool> tile;
578 Block(const CoordBBox& b) : bbox(b), leaf(nullptr) {}
579 };
580
581 const DenseT* mDense;
582 TreeT* mTree;
583 std::vector<Block>* mBlocks;
584 ValueT mTolerance;
585 std::unique_ptr<AccessorT> mAccessor;
586 };// CopyFromDense
587
588
589 // Convenient wrapper function for the CopyFromDense class
590 template<typename DenseT, typename GridOrTreeT>
591 void
592 copyFromDense(const DenseT& dense, GridOrTreeT& sparse,
593 const typename GridOrTreeT::ValueType& tolerance, bool serial)
594 {
595 using Adapter = TreeAdapter<GridOrTreeT>;
596 using TreeT = typename Adapter::TreeType;
597
598 CopyFromDense<TreeT, DenseT> op(dense, Adapter::tree(sparse), tolerance);
599 op.copy(serial);
600 }
601
602 } // namespace tools
603 } // namespace OPENVDB_VERSION_NAME
604 } // namespace openvdb
605
606 #endif // OPENVDB_TOOLS_DENSE_HAS_BEEN_INCLUDED
607
608 // Copyright (c) 2012-2017 DreamWorks Animation LLC
609 // All rights reserved. This software is distributed under the
610 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v4_0_2::tools::Dense::Ptr
SharedPtr< Dense > Ptr
Definition: Dense.h:211
openvdb::v4_0_2::tools::CopyToDense::ValueT
typename TreeT::ValueType ValueT
Definition: Dense.h:416
openvdb::v4_0_2::tools::CopyFromDense::CopyFromDense
CopyFromDense(const DenseT &dense, TreeT &tree, const ValueT &tolerance)
Definition: Dense.h:477
openvdb::v4_0_2::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:284
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutZYX >::xStride
size_t xStride() const
Return the stride of the array in the x direction ( = dimY*dimZ).
Definition: Dense.h:128
Types.h
openvdb::v4_0_2::tools::Dense::ConstPtr
SharedPtr< const Dense > ConstPtr
Definition: Dense.h:212
Formats.h
Utility routines to output nicely-formatted numeric values.
openvdb::v4_0_2::SharedPtr
std::shared_ptr< T > SharedPtr
Definition: Types.h:130
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutXYZ >::yStride
size_t yStride() const
Return the stride of the array in the y direction ( = dimX).
Definition: Dense.h:179
openvdb::v4_0_2::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:256
openvdb::v4_0_2::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::v4_0_2::tools::CopyToDense::DenseT
_DenseT DenseT
Definition: Dense.h:414
openvdb::v4_0_2::tools::Dense::offsetToCoord
Coord offsetToCoord(size_t n) const
Return the global coordinate corresponding to the specified linear offset.
Definition: Dense.h:360
openvdb::v4_0_2::tools::LayoutXYZ
Definition: Dense.h:92
openvdb::v4_0_2::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:324
openvdb::v4_0_2::util::formattedInt
FormattedInt< IntT > formattedInt(IntT n)
Definition: Formats.h:130
openvdb::v4_0_2::tools::CopyFromDense::TreeT
_TreeT TreeT
Definition: Dense.h:472
openvdb::v4_0_2::math::Coord::min
static Coord min()
Return the smallest possible coordinate.
Definition: Coord.h:67
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
openvdb::v4_0_2::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&#39;s value array given by unsigned coordinates (i...
Definition: Dense.h:112
openvdb::v4_0_2::tools::Dense::memoryLayout
static MemoryLayout memoryLayout()
Return the memory layout for this grid (see above for definitions).
Definition: Dense.h:263
openvdb::v4_0_2::tools::Dense::origin
const Coord & origin() const
Return the grid&#39;s origin in index coordinates.
Definition: Dense.h:278
openvdb::v4_0_2::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:294
i
tbb::atomic< Index32 > i
Definition: LeafBuffer.h:71
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutZYX >::zStride
static size_t zStride()
Return the stride of the array in the z direction ( = 1).
Definition: Dense.h:136
openvdb::v4_0_2::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:382
openvdb::v4_0_2::tools::Dense::valueCount
Index64 valueCount() const
Return the number of voxels contained in this grid.
Definition: Dense.h:281
openvdb::v4_0_2::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:261
data
T * data
Definition: LeafBuffer.h:71
openvdb::v4_0_2::tools::Dense::data
ValueT * data()
Return a raw pointer to this grid&#39;s value array.
Definition: Dense.h:267
openvdb::v4_0_2::tools::Dense::memUsage
Index64 memUsage() const
Return the memory footprint of this Dense grid in bytes.
Definition: Dense.h:366
openvdb::v4_0_2::tree::ValueAccessor::addLeaf
void addLeaf(LeafNodeT *leaf)
Add the specified leaf to this tree, possibly creating a child branch in the process. If the leaf node already exists, replace it.
Definition: ValueAccessor.h:374
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutZYX >::mBBox
const CoordBBox mBBox
Definition: Dense.h:142
openvdb::v4_0_2::tools::CopyToDense::copy
void copy(bool serial=false) const
Definition: Dense.h:421
openvdb::v4_0_2::tools::CopyFromDense::CopyFromDense
CopyFromDense(const CopyFromDense &other)
Definition: Dense.h:485
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutXYZ >::offsetToLocalCoord
Coord offsetToLocalCoord(size_t n) const
Return the index coordinate corresponding to the specified linear offset.
Definition: Dense.h:165
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutXYZ >::zStride
size_t zStride() const
Return the stride of the array in the y direction ( = dimX*dimY).
Definition: Dense.h:183
openvdb::v4_0_2::tools::CopyFromDense::LeafT
typename TreeT::LeafNodeType LeafT
Definition: Dense.h:474
Prune.h
Defined various multi-threaded utility functions for trees.
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutZYX >::DenseBase
DenseBase(const CoordBBox &bbox)
Protected constructor so as to prevent direct instantiation.
Definition: Dense.h:140
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutXYZ >::mBBox
const CoordBBox mBBox
Definition: Dense.h:189
openvdb::v4_0_2::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129
openvdb::v4_0_2::tools::CopyFromDense::operator()
void operator()(const tbb::blocked_range< size_t > &r) const
Public method called by tbb::parallel_for.
Definition: Dense.h:539
openvdb::v4_0_2::Index64
uint64_t Index64
Definition: Types.h:56
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutXYZ >::xStride
static size_t xStride()
Return the stride of the array in the x direction ( = 1).
Definition: Dense.h:175
openvdb::v4_0_2::tools::Dense::Dense
Dense(const CoordBBox &bbox, ValueT *data)
Construct a dense grid that wraps an external array.
Definition: Dense.h:242
Exceptions.h
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v4_0_2::tools::LayoutZYX
Definition: Dense.h:92
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutXYZ >::DenseBase
DenseBase(const CoordBBox &bbox)
Protected constructor so as to prevent direct instantiation.
Definition: Dense.h:187
openvdb::v4_0_2::math::Coord::max
static Coord max()
Return the largest possible coordinate.
Definition: Coord.h:70
openvdb::v4_0_2::tools::Dense::coordToOffset
size_t coordToOffset(const Coord &xyz) const
Return the linear offset into this grid&#39;s value array given by the specified signed coordinates...
Definition: Dense.h:351
openvdb::v4_0_2::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:592
openvdb
Definition: Exceptions.h:39
openvdb::v4_0_2::math::Coord::minComponent
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition: Coord.h:199
openvdb::v4_0_2::tools::CopyFromDense
Copy the values from a dense grid into an OpenVDB tree.
Definition: Dense.h:468
openvdb::v4_0_2::tools::CopyToDense
Copy an OpenVDB tree into an existing dense grid.
Definition: Dense.h:411
openvdb::v4_0_2::math::CoordBBox::max
const Coord & max() const
Definition: Coord.h:335
openvdb::v4_0_2::tools::Dense::bbox
const CoordBBox & bbox() const
Return the bounding box of the signed index domain of this grid.
Definition: Dense.h:275
openvdb::v4_0_2::tools::CopyToDense::operator()
void operator()(const CoordBBox &bbox) const
Public method called by tbb::parallel_for.
Definition: Dense.h:431
openvdb::v4_0_2::tools::CopyToDense::TreeT
_TreeT TreeT
Definition: Dense.h:415
openvdb::v4_0_2::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&#39;s value array given by unsigned coordinates (i...
Definition: Dense.h:159
openvdb::v4_0_2::tree::ValueAccessor< TreeT >
openvdb::v4_0_2::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:317
openvdb::v4_0_2::tools::Dense::Dense
Dense(const CoordBBox &bbox)
Construct a dense grid with a given range of coordinates.
Definition: Dense.h:219
openvdb::v4_0_2::tools::Dense::fill
void fill(const ValueT &value)
Fill this grid with a constant value.
Definition: Dense.h:338
openvdb::v4_0_2::tools::DenseBase
Base class for Dense which is defined below.
Definition: Dense.h:97
openvdb::v4_0_2::tools::CopyToDense::CopyToDense
CopyToDense(const TreeT &tree, DenseT &dense)
Definition: Dense.h:418
openvdb::v4_0_2::tools::Dense::data
const ValueT * data() const
Return a raw pointer to this grid&#39;s value array.
Definition: Dense.h:271
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutXYZ >::mZ
const size_t mZ
Definition: Dense.h:190
openvdb::v4_0_2::util::printBytes
OPENVDB_API int printBytes(std::ostream &os, uint64_t bytes, const std::string &head="", const std::string &tail="\, bool exact=false, int width=8, int precision=3)
openvdb::v4_0_2::tools::Dense::ValueType
ValueT ValueType
Definition: Dense.h:209
openvdb::v4_0_2::ValueError
Definition: Exceptions.h:92
openvdb::v4_0_2::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:332
ValueAccessor.h
openvdb::v4_0_2::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:287
Grid.h
openvdb::v4_0_2::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:290
openvdb::v4_0_2::tools::CopyFromDense::copy
void copy(bool serial=false)
Copy values from the dense grid to the sparse tree.
Definition: Dense.h:495
openvdb::v4_0_2::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:48
openvdb::v4_0_2::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:373
openvdb::v4_0_2::tools::MemoryLayout
MemoryLayout
Definition: Dense.h:92
openvdb::v4_0_2::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:445
openvdb::v4_0_2::tools::Dense
Dense is a simple dense grid API used by the CopyToDense and CopyFromDense classes defined below...
Definition: Dense.h:206
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v4_0_2::math::Coord::ValueType
Int32 ValueType
Definition: Coord.h:56
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutZYX >::yStride
size_t yStride() const
Return the stride of the array in the y direction ( = dimZ).
Definition: Dense.h:132
openvdb::v4_0_2::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:227
openvdb::v4_0_2::math::CoordBBox::min
const Coord & min() const
Definition: Coord.h:334
openvdb::v4_0_2::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:943
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutZYX >::offsetToLocalCoord
Coord offsetToLocalCoord(size_t n) const
Return the local coordinate corresponding to the specified linear offset.
Definition: Dense.h:118
openvdb::v4_0_2::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, j, k).
Definition: Dense.h:302
openvdb::v4_0_2::tools::CopyFromDense::ValueT
typename TreeT::ValueType ValueT
Definition: Dense.h:473
size
static constexpr size_t size
The size of a LeafBuffer when LeafBuffer::mOutOfCore is atomic.
Definition: LeafBuffer.h:85
openvdb::v4_0_2::tools::DenseBase< ValueT, LayoutZYX >::mY
const size_t mY
Definition: Dense.h:143
openvdb::v4_0_2::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:310
openvdb::v4_0_2::tools::CopyFromDense::DenseT
_DenseT DenseT
Definition: Dense.h:471