Skip to content

Commit 4a71881

Browse files
authored
Merge pull request #1584 from kmuseth/fix_IteratorRange
Fixed precision bug in tree::RangeIterator
2 parents 6d1ff04 + 89be525 commit 4a71881

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

openvdb/openvdb/tree/TreeIterator.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,13 +1302,20 @@ template<typename IterT>
13021302
class IteratorRange
13031303
{
13041304
public:
1305+
/// @brief Constructor from iterator and grain size
1306+
/// @param iter Iterator from which the range is constructed
1307+
/// @param grainSize Grain size which controls the granularity of range splitting
13051308
IteratorRange(const IterT& iter, size_t grainSize = 8):
13061309
mIter(iter),
13071310
mGrainSize(grainSize),
13081311
mSize(0)
13091312
{
13101313
mSize = this->size();
13111314
}
1315+
1316+
/// @brief Split constructor used by tbb (should rarely be called directly)
1317+
/// @param other IteratorRange to be split
1318+
/// @param tbb::split Dummy class used to create a unique signature for this constructor
13121319
IteratorRange(IteratorRange& other, tbb::split):
13131320
mIter(other.mIter),
13141321
mGrainSize(other.mGrainSize),
@@ -1331,24 +1338,23 @@ class IteratorRange
13311338
bool is_divisible() const { return mSize > mGrainSize; }
13321339

13331340
/// Advance the iterator @a n times.
1334-
void increment(Index n = 1) { for ( ; n > 0 && mSize > 0; --n, --mSize, ++mIter) {} }
1341+
void increment(size_t n = 1) { for ( ; n > 0 && mSize > 0; --n, --mSize, ++mIter) {} }
13351342
/// Advance the iterator to the next item.
13361343
IteratorRange& operator++() { this->increment(); return *this; }
13371344
/// @brief Advance the iterator to the next item.
13381345
/// @return @c true if the iterator is not yet exhausted.
13391346
bool next() { this->increment(); return this->test(); }
13401347

13411348
private:
1342-
Index size() const { Index n = 0; for (IterT it(mIter); it.test(); ++n, ++it) {} return n; }
1349+
size_t size() const { size_t n = 0; for (IterT it(mIter); it.test(); ++n, ++it) {} return n; }
13431350

13441351
IterT mIter;
1345-
size_t mGrainSize;
1352+
size_t mGrainSize, mSize;
13461353
/// @note mSize is only an estimate of the number of times mIter can be incremented
13471354
/// before it is exhausted (because the topology of the underlying tree could change
13481355
/// during iteration). For the purpose of range splitting, though, that should be
13491356
/// sufficient, since the two halves need not be of exactly equal size.
1350-
Index mSize;
1351-
};
1357+
};// class IteratorRange
13521358

13531359

13541360
////////////////////////////////////////
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Bug-fix:
2+
- Internal counters in tree::RangeIterator were limited to 32bit precision. They are now extended to size_t. (reported by SpaceX)

0 commit comments

Comments
 (0)