diff --git a/include/E57SimpleWriter.h b/include/E57SimpleWriter.h index dd311fd..6963019 100644 --- a/include/E57SimpleWriter.h +++ b/include/E57SimpleWriter.h @@ -75,11 +75,28 @@ namespace e57 //! @name Image2D //!@{ + //! @brief This function writes the Image2D data to the file + //! @details The user needs to config a Image2D structure with all the camera information before making this call. + //! @note @p image2DHeader may be modified (adding a guid or adding missing, required fields). + //! @param [in,out] image2DHeader header metadata + //! @param [in] imageType identifies the image format + //! @param [in] imageProjection identifies the projection + //! @param [in] startPos position in the block to start writing + //! @param [in] buffer pointer the data buffer + //! @param [in] byteCount buffer size + //! @return Returns the number of bytes written + int64_t WriteImage2DData( Image2D &image2DHeader, Image2DType imageType, Image2DProjection imageProjection, + int64_t startPos, void *buffer, int64_t byteCount ); + //! @brief Writes a new Image2D header //! @details The user needs to config a Image2D structure with all the camera information before making this call. //! @param [in,out] image2DHeader header metadata //! @return Returns the image2D index - int64_t NewImage2D( Image2D &image2DHeader ); + //! @deprecated Will be removed in 4.0. Use WriteImage2DData(Image2D &,Image2DType,Image2DProjection,int64_t,void + //! *,int64_t) instead. + [[deprecated( "Will be removed in 4.0. Use WriteImage2DData()." )]] // TODO Remove in 4.0 + int64_t + NewImage2D( Image2D &image2DHeader ); //! @brief Writes the actual image data //! @param [in] imageIndex picture block index given by the NewImage2D @@ -89,32 +106,55 @@ namespace e57 //! @param [in] start position in the block to start writing //! @param [in] count size of desired chunk or buffer size //! @return Returns the number of bytes written - int64_t WriteImage2DData( int64_t imageIndex, Image2DType imageType, Image2DProjection imageProjection, - void *buffer, int64_t start, int64_t count ); + //! @deprecated Will be removed in 4.0. Use WriteImage2DData(Image2D &,Image2DType,Image2DProjection,int64_t,void + //! *,int64_t) instead. + [[deprecated( "Will be removed in 4.0. Use WriteImage2DData(Image2D &,Image2DType,Image2DProjection,int64_t,void " + "*,int64_t)." )]] // TODO Remove in 4.0 + int64_t + WriteImage2DData( int64_t imageIndex, Image2DType imageType, Image2DProjection imageProjection, void *buffer, + int64_t start, int64_t count ); //!@} //! @name Data3D //!@{ - //! @brief Writes new Data3D header + //! @brief This function writes the Data3D data to the file + //! @details The user needs to config a Data3D structure with all the scanning information before making this + //! call. + //! @note @p data3DHeader may be modified (adding a guid or adding missing, required fields). + //! @param [in,out] data3DHeader metadata about what is included in the buffers + //! @param [in] buffers pointers to user-provided buffers containing the actual data + //! @return Returns the index of the new scan's data3D block. + int64_t WriteData3DData( Data3D &data3DHeader, const Data3DPointsData &buffers ); + + //! @overload + int64_t WriteData3DData( Data3D &data3DHeader, const Data3DPointsData_d &buffers ); + + //! @brief Writes a new Data3D header //! @details The user needs to config a Data3D structure with all the scanning information before making this //! call. //! @param [in,out] data3DHeader scan metadata //! @return Returns the index of the new scan's data3D block. - int64_t NewData3D( Data3D &data3DHeader ); + //! @deprecated Will be removed in 4.0. Use WriteData3DData() instead. + [[deprecated( "Will be removed in 4.0. Use WriteData3DData()." )]] // TODO Remove in 4.0 + int64_t + NewData3D( Data3D &data3DHeader ); //! @brief Sets up a writer to write the actual scan data //! @param [in] dataIndex index returned by NewData3D //! @param [in] pointCount Number of points to write (number of elements in each of the buffers) //! @param [in] buffers pointers to user-provided buffers //! @return returns a vector writer setup to write the selected scan data - CompressedVectorWriter SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, - const Data3DPointsData &buffers ); + //! @deprecated Will be removed in 4.0. Use WriteData3DData() instead. + [[deprecated( "Will be removed in 4.0. Use WriteData3DData()." )]] // TODO Remove in 4.0 + CompressedVectorWriter + SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, const Data3DPointsData &buffers ); //! @overload - CompressedVectorWriter SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, - const Data3DPointsData_d &buffers ); + [[deprecated( "Will be removed in 4.0. Use WriteData3DData()." )]] // TODO Remove in 4.0 + CompressedVectorWriter + SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, const Data3DPointsData_d &buffers ); //! @brief Writes out the group data //! @param [in] dataIndex data block index given by the NewData3D diff --git a/src/E57SimpleWriter.cpp b/src/E57SimpleWriter.cpp index 1ba8690..cd1de7a 100644 --- a/src/E57SimpleWriter.cpp +++ b/src/E57SimpleWriter.cpp @@ -50,26 +50,20 @@ namespace e57 bool Writer::Close() { return impl_->Close(); - }; - - ImageFile Writer::GetRawIMF() - { - return impl_->GetRawIMF(); } - StructureNode Writer::GetRawE57Root() + int64_t Writer::WriteImage2DData( Image2D &image2DHeader, Image2DType imageType, Image2DProjection imageProjection, + int64_t startPos, void *pBuffer, int64_t byteCount ) { - return impl_->GetRawE57Root(); - }; + auto *buffer = static_cast( pBuffer ); + const auto sizeInBytes = static_cast( byteCount ); - VectorNode Writer::GetRawData3D() - { - return impl_->GetRawData3D(); - }; + const int64_t imageIndex = impl_->NewImage2D( image2DHeader ); - VectorNode Writer::GetRawImages2D() - { - return impl_->GetRawImages2D(); + const size_t written = + impl_->WriteImage2DData( imageIndex, imageType, imageProjection, buffer, startPos, sizeInBytes ); + + return static_cast( written ); }; int64_t Writer::NewImage2D( Image2D &image2DHeader ) @@ -88,6 +82,32 @@ namespace e57 return static_cast( written ); } + int64_t Writer::WriteData3DData( Data3D &data3DHeader, const Data3DPointsData &buffers ) + { + const int64_t scanIndex = impl_->NewData3D( data3DHeader ); + + e57::CompressedVectorWriter dataWriter = + impl_->SetUpData3DPointsData( scanIndex, data3DHeader.pointCount, buffers ); + + dataWriter.write( data3DHeader.pointCount ); + dataWriter.close(); + + return scanIndex; + } + + int64_t Writer::WriteData3DData( Data3D &data3DHeader, const Data3DPointsData_d &buffers ) + { + const int64_t scanIndex = impl_->NewData3D( data3DHeader ); + + e57::CompressedVectorWriter dataWriter = + impl_->SetUpData3DPointsData( scanIndex, data3DHeader.pointCount, buffers ); + + dataWriter.write( data3DHeader.pointCount ); + dataWriter.close(); + + return scanIndex; + } + int64_t Writer::NewData3D( Data3D &data3DHeader ) { return impl_->NewData3D( data3DHeader ); @@ -110,4 +130,24 @@ namespace e57 { return impl_->WriteData3DGroupsData( dataIndex, groupCount, idElementValue, startPointIndex, pointCount ); } + + ImageFile Writer::GetRawIMF() + { + return impl_->GetRawIMF(); + } + + StructureNode Writer::GetRawE57Root() + { + return impl_->GetRawE57Root(); + }; + + VectorNode Writer::GetRawData3D() + { + return impl_->GetRawData3D(); + }; + + VectorNode Writer::GetRawImages2D() + { + return impl_->GetRawImages2D(); + }; } // end namespace e57 diff --git a/test/src/test_SimpleData.cpp b/test/src/test_SimpleData.cpp index fd0de24..48e2e4b 100644 --- a/test/src/test_SimpleData.cpp +++ b/test/src/test_SimpleData.cpp @@ -102,13 +102,7 @@ TEST( SimpleData, ReadWrite ) e57::Writer *writer = nullptr; E57_ASSERT_NO_THROW( writer = new e57::Writer( "./ColouredCubeDoubleCopy.e57", options ) ); - const int64_t cScanIndex1 = writer->NewData3D( originalData3DHeader ); - const uint16_t cNumPoints = originalData3DHeader.pointCount; - - auto dataWriter = writer->SetUpData3DPointsData( cScanIndex1, cNumPoints, *originalPointsData ); - - dataWriter.write( cNumPoints ); - dataWriter.close(); + writer->WriteData3DData( originalData3DHeader, *originalPointsData ); delete writer; } diff --git a/test/src/test_SimpleWriter.cpp b/test/src/test_SimpleWriter.cpp index f7b9094..6525ec7 100644 --- a/test/src/test_SimpleWriter.cpp +++ b/test/src/test_SimpleWriter.cpp @@ -192,12 +192,7 @@ TEST( SimpleWriter, ColouredCubeDouble ) generateCubePoints( 1.0, cNumPointsPerFace, writePointLambda ); - const int64_t cScanIndex1 = writer->NewData3D( header ); - - e57::CompressedVectorWriter dataWriter = writer->SetUpData3DPointsData( cScanIndex1, cNumPoints, pointsData ); - - dataWriter.write( cNumPoints ); - dataWriter.close(); + writer->WriteData3DData( header, pointsData ); delete writer; } @@ -255,12 +250,7 @@ TEST( SimpleWriter, ColouredCubeFloat ) generateCubePoints( 1.0, cNumPointsPerFace, writePointLambda ); - const int64_t cScanIndex1 = writer->NewData3D( header ); - - e57::CompressedVectorWriter dataWriter = writer->SetUpData3DPointsData( cScanIndex1, cNumPoints, pointsData ); - - dataWriter.write( cNumPoints ); - dataWriter.close(); + writer->WriteData3DData( header, pointsData ); delete writer; } @@ -315,12 +305,7 @@ TEST( SimpleWriter, ColouredCubeScaledInt ) generateCubePoints( 1.0, cNumPointsPerFace, writePointLambda ); - const int64_t cScanIndex1 = writer->NewData3D( header ); - - e57::CompressedVectorWriter dataWriter = writer->SetUpData3DPointsData( cScanIndex1, cNumPoints, pointsData ); - - dataWriter.write( cNumPoints ); - dataWriter.close(); + writer->WriteData3DData( header, pointsData ); delete writer; } @@ -347,8 +332,6 @@ TEST( SimpleWriter, MultipleScans ) // scan 1 header.guid = "Multiple Scans Scan 1 Header GUID"; - const int64_t cScanIndex1 = writer->NewData3D( header ); - int64_t i = 0; auto writePointLambda = [&]( const Point &point ) { pointsData.cartesianX[i] = point[0]; @@ -359,23 +342,15 @@ TEST( SimpleWriter, MultipleScans ) generateCubeCornerPoints( 1.0, writePointLambda ); - e57::CompressedVectorWriter dataWriter = writer->SetUpData3DPointsData( cScanIndex1, cNumPoints, pointsData ); - - dataWriter.write( cNumPoints ); - dataWriter.close(); + writer->WriteData3DData( header, pointsData ); // scan 2 header.guid = "Multiple Scans Scan 2 Header GUID"; - const int64_t cScanIndex2 = writer->NewData3D( header ); - i = 0; generateCubeCornerPoints( 0.5, writePointLambda ); - dataWriter = writer->SetUpData3DPointsData( cScanIndex2, cNumPoints, pointsData ); - - dataWriter.write( cNumPoints ); - dataWriter.close(); + writer->WriteData3DData( header, pointsData ); delete writer; } @@ -416,8 +391,6 @@ TEST( SimpleWriter, CartesianPoints ) header.pointFields.cartesianYField = true; header.pointFields.cartesianZField = true; - const int64_t scanIndex = writer->NewData3D( header ); - e57::Data3DPointsData pointsData( header ); for ( int64_t i = 0; i < cNumPoints; ++i ) @@ -428,10 +401,7 @@ TEST( SimpleWriter, CartesianPoints ) pointsData.cartesianZ[i] = floati; } - e57::CompressedVectorWriter dataWriter = writer->SetUpData3DPointsData( scanIndex, cNumPoints, pointsData ); - - dataWriter.write( cNumPoints ); - dataWriter.close(); + writer->WriteData3DData( header, pointsData ); delete writer; } @@ -453,8 +423,6 @@ TEST( SimpleWriter, ColouredCartesianPoints ) setUsingColouredCartesianPoints( header ); - const int64_t scanIndex = writer->NewData3D( header ); - e57::Data3DPointsData pointsData( header ); for ( int64_t i = 0; i < cNumPoints; ++i ) @@ -469,10 +437,7 @@ TEST( SimpleWriter, ColouredCartesianPoints ) pointsData.colorBlue[i] = 255; } - e57::CompressedVectorWriter dataWriter = writer->SetUpData3DPointsData( scanIndex, cNumPoints, pointsData ); - - dataWriter.write( cNumPoints ); - dataWriter.close(); + writer->WriteData3DData( header, pointsData ); delete writer; } @@ -509,9 +474,7 @@ TEST( SimpleWriterData, VisualRefImage ) image2DHeader.visualReferenceRepresentation.imageHeight = 300; image2DHeader.visualReferenceRepresentation.jpegImageSize = cImageSize; - int64_t imageIndex = writer->NewImage2D( image2DHeader ); - - writer->WriteImage2DData( imageIndex, e57::E57_JPEG_IMAGE, e57::E57_VISUAL, imageBuffer, 0, cImageSize ); + writer->WriteImage2DData( image2DHeader, e57::E57_JPEG_IMAGE, e57::E57_VISUAL, 0, imageBuffer, cImageSize ); delete[] imageBuffer;