Skip to content

Commit

Permalink
{standard} Read a properly-formed compressed vector with 0 points
Browse files Browse the repository at this point in the history
A compressed vector with 0 points must still have a data packet.

Part of #262
  • Loading branch information
asmaloney committed Oct 26, 2023
1 parent d4d5496 commit 43d19e2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/CompressedVectorReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,16 @@ namespace e57
"packetType=" + toString( dpkt->header.packetType ) );
}

// Have good packet, initialize channels
for ( auto &channel : channels_ )
// Have good packet, initialize channels if we have records
if ( maxRecordCount_ > 0 )
{
channel.currentPacketLogicalOffset = dataLogicalOffset;
channel.currentBytestreamBufferIndex = 0;
channel.currentBytestreamBufferLength =
dpkt->getBytestreamBufferLength( channel.bytestreamNumber );
for ( auto &channel : channels_ )
{
channel.currentPacketLogicalOffset = dataLogicalOffset;
channel.currentBytestreamBufferIndex = 0;
channel.currentBytestreamBufferLength =
dpkt->getBytestreamBufferLength( channel.bytestreamNumber );
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions test/src/test_SimpleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,42 @@ TEST( SimpleReaderData, Empty )
delete reader;
}

TEST( SimpleReaderData, ZeroPoints )
{
e57::Reader *reader = nullptr;

E57_ASSERT_NO_THROW( reader = new e57::Reader( TestData::Path() + "/self/ZeroPoints.e57", {} ) );

ASSERT_TRUE( reader->IsOpen() );
EXPECT_EQ( reader->GetImage2DCount(), 0 );
EXPECT_EQ( reader->GetData3DCount(), 1 );

e57::E57Root fileHeader;
ASSERT_TRUE( reader->GetE57Root( fileHeader ) );

CheckFileHeader( fileHeader );
EXPECT_EQ( fileHeader.guid, "Zero Points GUID" );

e57::Data3D data3DHeader;
ASSERT_TRUE( reader->ReadData3D( 0, data3DHeader ) );

ASSERT_EQ( data3DHeader.pointCount, 0 );

const uint64_t cNumPoints = data3DHeader.pointCount;

e57::Data3DPointsFloat pointsData( data3DHeader );

auto vectorReader = reader->SetUpData3DPointsData( 0, cNumPoints, pointsData );

const uint64_t cNumRead = vectorReader.read();

vectorReader.close();

EXPECT_EQ( cNumRead, cNumPoints );

delete reader;
}

TEST( SimpleReaderData, ZeroPointsInvalid )
{
e57::Reader *reader = nullptr;
Expand Down

0 comments on commit 43d19e2

Please sign in to comment.