Skip to content

Adds packet index skip flag #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/E57Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ public:
VectorNode codecs() const;

// Iterators
CompressedVectorWriter writer( std::vector<SourceDestBuffer> &sbufs );
CompressedVectorWriter writer( std::vector<SourceDestBuffer> &sbufs,
bool writeIndexPackets = true );
CompressedVectorReader reader( const std::vector<SourceDestBuffer> &dbufs );

// Up/Down cast conversion
Expand Down
3 changes: 3 additions & 0 deletions include/E57SimpleWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace e57

/// Information describing the Coordinate Reference System to be used for the file
ustring coordinateMetadata;

/// Write the index packets (setting this to false is not standards compliant)
bool writeIndexPackets = true;
};

/// @brief Used for writing an E57 file using the E57 Simple API.
Expand Down
5 changes: 3 additions & 2 deletions src/CompressedVectorNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,10 @@ CompressedVectorNode cannot be set twice).
@see CompressedVectorWriter, SourceDestBuffer, CompressedVectorNode::CompressedVectorNode,
CompressedVectorNode::prototype
*/
CompressedVectorWriter CompressedVectorNode::writer( std::vector<SourceDestBuffer> &sbufs )
CompressedVectorWriter CompressedVectorNode::writer( std::vector<SourceDestBuffer> &sbufs,
bool writeIndexPackets )
{
return CompressedVectorWriter( impl_->writer( sbufs ) );
return CompressedVectorWriter( impl_->writer( sbufs, writeIndexPackets ) );
}

/*!
Expand Down
4 changes: 2 additions & 2 deletions src/CompressedVectorNodeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ namespace e57
#endif

std::shared_ptr<CompressedVectorWriterImpl> CompressedVectorNodeImpl::writer(
std::vector<SourceDestBuffer> sbufs )
std::vector<SourceDestBuffer> sbufs, bool writeIndexPackets )
{
checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );

Expand Down Expand Up @@ -313,7 +313,7 @@ namespace e57

// Return a shared_ptr to new object
std::shared_ptr<CompressedVectorWriterImpl> cvwi(
new CompressedVectorWriterImpl( cai, sbufs ) );
new CompressedVectorWriterImpl( cai, sbufs, writeIndexPackets ) );
return ( cvwi );
}

Expand Down
3 changes: 2 additions & 1 deletion src/CompressedVectorNodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace e57
const char *forcedFieldName = nullptr ) override;

/// Iterator constructors
std::shared_ptr<CompressedVectorWriterImpl> writer( std::vector<SourceDestBuffer> sbufs );
std::shared_ptr<CompressedVectorWriterImpl> writer( std::vector<SourceDestBuffer> sbufs,
bool writeIndexPackets = true );
std::shared_ptr<CompressedVectorReaderImpl> reader( std::vector<SourceDestBuffer> dbufs );

int64_t getRecordCount() const
Expand Down
12 changes: 8 additions & 4 deletions src/CompressedVectorWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ namespace e57
};

CompressedVectorWriterImpl::CompressedVectorWriterImpl(
std::shared_ptr<CompressedVectorNodeImpl> ni, std::vector<SourceDestBuffer> &sbufs ) :
cVector_( ni ), isOpen_( false ) // set to true when succeed below
std::shared_ptr<CompressedVectorNodeImpl> ni, std::vector<SourceDestBuffer> &sbufs,
bool writeIndexPackets ) :
cVector_( ni ), writeIndexPackets_(writeIndexPackets), isOpen_( false ) // set to true when succeed below
{
//??? check if cvector already been written (can't write twice)

Expand Down Expand Up @@ -183,8 +184,11 @@ namespace e57
flush();
}

// Write one index packet (required by standard).
packetWriteIndex();
if (writeIndexPackets_)
{
// Write one index packet (required by standard).
packetWriteIndex();
}

// Compute length of whole section we just wrote (from section start to
// current start of free space).
Expand Down
4 changes: 3 additions & 1 deletion src/CompressedVectorWriterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ namespace e57
{
public:
CompressedVectorWriterImpl( std::shared_ptr<CompressedVectorNodeImpl> ni,
std::vector<SourceDestBuffer> &sbufs );
std::vector<SourceDestBuffer> &sbufs,
bool writeIndexPackets = true );
~CompressedVectorWriterImpl();

void write( size_t requestedRecordCount );
Expand Down Expand Up @@ -69,6 +70,7 @@ namespace e57
std::vector<std::shared_ptr<Encoder>> bytestreams_;
DataPacket dataPacket_;

bool writeIndexPackets_; /// set this to false for backwards compatibility
bool isOpen_;
uint64_t sectionHeaderLogicalStart_; /// start of CompressedVector binary section
uint64_t sectionLogicalLength_; /// total length of CompressedVector binary section
Expand Down
7 changes: 4 additions & 3 deletions src/WriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ namespace e57
}

WriterImpl::WriterImpl( const ustring &filePath, const WriterOptions &options ) :
imf_( filePath, "w" ), root_( imf_.root() ), data3D_( imf_, true ), images2D_( imf_, true )
imf_( filePath, "w" ), root_( imf_.root() ), data3D_( imf_, true ), images2D_( imf_, true ),
writeIndexPackets_(options.writeIndexPackets)
{
// We are using the E57 v1.0 data format standard field names.
// The standard field names are used without an extension prefix (in the default namespace).
Expand Down Expand Up @@ -1295,7 +1296,7 @@ namespace e57
}

// create the writer, all buffers must be setup before this call
CompressedVectorWriter writer = points.writer( sourceBuffers );
CompressedVectorWriter writer = points.writer( sourceBuffers, writeIndexPackets_ );

return writer;
}
Expand Down Expand Up @@ -1345,7 +1346,7 @@ namespace e57
groupSDBuffers.emplace_back( imf_, "startPointIndex", startPointIndex, groupCount, true );
groupSDBuffers.emplace_back( imf_, "pointCount", pointCount, groupCount, true );

CompressedVectorWriter writer = groups.writer( groupSDBuffers );
CompressedVectorWriter writer = groups.writer( groupSDBuffers, writeIndexPackets_ );
writer.write( groupCount );
writer.close();

Expand Down
2 changes: 2 additions & 0 deletions src/WriterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,7 @@ namespace e57
VectorNode data3D_;

VectorNode images2D_;

bool writeIndexPackets_;
}; // end Writer class
} // end namespace e57
48 changes: 48 additions & 0 deletions test/src/test_SimpleWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,51 @@ TEST( SimpleWriterData, VisualRefImage )

delete writer;
}

TEST( SimpleWriter, WritePacketIsTrueByDefault)
{
e57::WriterOptions options;

EXPECT_TRUE( options.writeIndexPackets );
}

TEST( SimpleWriter, PacketWriteIndexFlag )
{
e57::WriterOptions options;
options.guid = "Packet Write Index Test GUID";
options.writeIndexPackets = false;

e57::Writer *writer = nullptr;

E57_ASSERT_NO_THROW( writer = new e57::Writer( "./PacketWriteIndexFalse.e57", options ) );

constexpr int64_t cNumPoints = 10;

e57::Data3D header;
header.guid = "PacketWriteIndexFalse Header GUID";
header.pointCount = cNumPoints;
header.pointFields.cartesianXField = true;
header.pointFields.cartesianYField = true;
header.pointFields.cartesianZField = true;

e57::Data3DPointsFloat pointsData( header );

for ( int64_t i = 0; i < cNumPoints; ++i )
{
auto floati = static_cast<float>( i );
pointsData.cartesianX[i] = floati;
pointsData.cartesianY[i] = floati;
pointsData.cartesianZ[i] = floati;
}

try
{
writer->WriteData3DData( header, pointsData );
}
catch ( e57::E57Exception &err )
{
FAIL() << err.errorStr() << ": " << err.context();
}

delete writer;
}