Skip to content

Commit

Permalink
VoxelGraphCut: in sub-tasks allocate smaller bit-sets (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedr authored Apr 28, 2023
1 parent 7ecf070 commit 8becf8d
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 81 deletions.
9 changes: 9 additions & 0 deletions source/MRMesh/MRBitSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ BitSet & BitSet::operator -= ( const BitSet & rhs )
return *this;
}

BitSet & BitSet::subtract( const BitSet & b, int bShiftInBlocks )
{
const auto beginBlock = std::max( 0, bShiftInBlocks );
const auto endBlock = std::clamp( b.num_blocks() + bShiftInBlocks, size_t(0), num_blocks() );
for ( size_type i = beginBlock; i < endBlock; ++i )
m_bits[i] &= ~b.m_bits[i - bShiftInBlocks];
return *this;
}

bool operator == ( const BitSet & a, const BitSet & b )
{
if ( a.size() == b.size() )
Expand Down
4 changes: 4 additions & 0 deletions source/MRMesh/MRBitSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class BitSet : public boost::dynamic_bitset<std::uint64_t>
MRMESH_API BitSet & operator |= ( const BitSet & b );
MRMESH_API BitSet & operator ^= ( const BitSet & b );
MRMESH_API BitSet & operator -= ( const BitSet & b );
/// subtracts b from this, considering that bits in b are shifted right on bShiftInBlocks*bits_per_block
MRMESH_API BitSet & subtract( const BitSet & b, int bShiftInBlocks );

/// return the highest index i such as bit i is set, or npos if *this has no on bits.
[[nodiscard]] MRMESH_API IndexType find_last() const;
Expand Down Expand Up @@ -109,6 +111,8 @@ class TaggedBitSet : public BitSet
TaggedBitSet & operator |= ( const TaggedBitSet & b ) { base::operator |= ( b ); return * this; }
TaggedBitSet & operator ^= ( const TaggedBitSet & b ) { base::operator ^= ( b ); return * this; }
TaggedBitSet & operator -= ( const TaggedBitSet & b ) { base::operator -= ( b ); return * this; }
/// subtracts b from this, considering that bits in b are shifted right on bShiftInBlocks*bits_per_block
TaggedBitSet & subtract( const TaggedBitSet & b, int bShiftInBlocks ) { base::subtract( b, bShiftInBlocks ); return * this; }

void autoResizeSet( IndexType pos, size_type len, bool val = true ) { base::autoResizeSet( pos, len, val ); }
void autoResizeSet( IndexType pos, bool val = true ) { base::autoResizeSet( pos, val ); }
Expand Down
Loading

0 comments on commit 8becf8d

Please sign in to comment.