Skip to content

Commit

Permalink
fix glitch with selected points (#2808)
Browse files Browse the repository at this point in the history
* fix glitch with selected points

* copy points only when seection is less than point count

* avoid extra copy

* some refactoring
  • Loading branch information
astrowander authored Jun 4, 2024
1 parent a915986 commit 56c0c8f
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions source/MRViewer/MRRenderPointsObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,22 +416,24 @@ RenderBufferRef<unsigned> RenderPointsObject::loadVertSelectionTextureBuffer_()

const auto& points = objPoints_->pointCloud();
const auto step = objPoints_->getRenderDiscretization();
const auto numV = ( points->validPoints.find_last() + 1 ) / int( step );
const int num = points->validPoints.find_last() + 1;
const auto numV = num / int( step );
auto size = numV / 32 + 1;
vertSelectionTextureSize_ = calcTextureRes( size, maxTexSize_ );
assert( vertSelectionTextureSize_.x * vertSelectionTextureSize_.y >= size );
auto buffer = glBuffer.prepareBuffer<unsigned>( vertSelectionTextureSize_.x * vertSelectionTextureSize_.y );

const auto& selection = objPoints_->getSelectedPoints().m_bits;
const unsigned* selectionData = (unsigned*) selection.data();
const auto& selectedPoints = objPoints_->getSelectedPoints();
const size_t selectionSize = selectedPoints.m_bits.size();

const unsigned* selectionData = ( unsigned* )selectedPoints.m_bits.data();

ParallelFor( 0, ( int )buffer.size(), [&]( int r )
{
auto& block = buffer[r];
if ( r * step / 2 >= selection.size() )
{
block = 0;
block = 0;
if ( r * step / 2 >= selectionSize )
return;
}

if ( step == 1 )
{
Expand All @@ -441,11 +443,13 @@ RenderBufferRef<unsigned> RenderPointsObject::loadVertSelectionTextureBuffer_()

for ( int bit = 0; bit < 32; ++bit )
{
const auto selectionBit = std::div( ( r * 32 + bit ) * int( step ), 32 );
const int bitIndex = ( r * 32 + bit ) * int( step );
if ( bitIndex >= selectionSize * 64 )
continue;

const auto selectionBit = std::div( bitIndex, 32 );
if ( selectionData[selectionBit.quot] & ( 1 << ( selectionBit.rem ) ) )
block |= 1 << bit;
else
block &= ~( 1 << bit );
}
} );

Expand Down

0 comments on commit 56c0c8f

Please sign in to comment.