From aef4fd775259234244766ef486e424c17644da47 Mon Sep 17 00:00:00 2001 From: gjacquem <75491316+gjacquem@users.noreply.github.com> Date: Thu, 7 Jan 2021 11:34:20 +0100 Subject: [PATCH] Templatize E57Simple to support double coordinates (#63) The E57Simple API only supports float coordinates. Added template to work with either float or double. --- include/E57SimpleData.h | 18 +++++++++++------- include/E57SimpleReader.h | 10 ++++++++++ include/E57SimpleWriter.h | 8 ++++++++ src/E57SimpleReader.cpp | 6 ++++++ src/E57SimpleWriter.cpp | 6 ++++++ src/ReaderImpl.cpp | 10 +++++++++- src/ReaderImpl.h | 3 ++- src/WriterImpl.cpp | 10 +++++++++- src/WriterImpl.h | 3 ++- 9 files changed, 63 insertions(+), 11 deletions(-) diff --git a/include/E57SimpleData.h b/include/E57SimpleData.h index 72315de..689d4df 100644 --- a/include/E57SimpleData.h +++ b/include/E57SimpleData.h @@ -435,15 +435,16 @@ namespace e57 }; //! @brief Stores pointers to user-provided buffers - struct E57_DLL Data3DPointsData + template + struct Data3DPointsData_t { - float *cartesianX{ + COORDTYPE *cartesianX{ nullptr }; //!< pointer to a buffer with the X coordinate (in meters) of the point in Cartesian coordinates - float *cartesianY{ + COORDTYPE *cartesianY{ nullptr }; //!< pointer to a buffer with the Y coordinate (in meters) of the point in Cartesian coordinates - float *cartesianZ{ + COORDTYPE *cartesianZ{ nullptr }; //!< pointer to a buffer with the Z coordinate (in meters) of the point in Cartesian coordinates int8_t *cartesianInvalidState{ nullptr }; //!< Value = 0 if the point is considered valid, 1 otherwise @@ -456,13 +457,13 @@ namespace e57 uint8_t *colorBlue{ nullptr }; //!< pointer to a buffer with the Blue color coefficient. Unit is unspecified int8_t *isColorInvalid{ nullptr }; //!< Value = 0 if the color is considered valid, 1 otherwise - float *sphericalRange{ + COORDTYPE *sphericalRange{ nullptr }; //!< pointer to a buffer with the range (in meters) of points in spherical coordinates. Shall be non-negative - float *sphericalAzimuth{ + COORDTYPE *sphericalAzimuth{ nullptr }; //!< pointer to a buffer with the Azimuth angle (in radians) of point in spherical coordinates - float *sphericalElevation{ + COORDTYPE *sphericalElevation{ nullptr }; //!< pointer to a buffer with the Elevation angle (in radians) of point in spherical coordinates int8_t *sphericalInvalidState{ nullptr }; //!< Value = 0 if the range is considered valid, 1 otherwise @@ -494,6 +495,9 @@ namespace e57 float *normalZ{ nullptr }; //!< The Z component of a surface normal vector (E57_EXT_surface_normals). }; + typedef Data3DPointsData_t Data3DPointsData; + typedef Data3DPointsData_t Data3DPointsData_d; + //! @brief Stores an image that is to be used only as a visual reference. struct E57_DLL VisualReferenceRepresentation { diff --git a/include/E57SimpleReader.h b/include/E57SimpleReader.h index a5d7561..1874238 100644 --- a/include/E57SimpleReader.h +++ b/include/E57SimpleReader.h @@ -145,6 +145,16 @@ namespace e57 CompressedVectorReader SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, const Data3DPointsData &buffers ) const; + //! @brief Use this function to read the actual 3D data + //! @details All the non-NULL buffers in buffers have number of elements = pointCount. + //! Call the CompressedVectorReader::read() until all data is read. + //! @param [in] dataIndex data block index given by the NewData3D + //! @param [in] pointCount size of each element buffer. + //! @param [in] buffers pointers to user-provided buffers + //! @return vector reader setup to read the selected data into the provided buffers + CompressedVectorReader SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, + const Data3DPointsData_d &buffers ) const; + //!@} //! @name Foundation API file information diff --git a/include/E57SimpleWriter.h b/include/E57SimpleWriter.h index 3c4ed35..9c21470 100644 --- a/include/E57SimpleWriter.h +++ b/include/E57SimpleWriter.h @@ -91,6 +91,14 @@ namespace e57 CompressedVectorWriter SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, const Data3DPointsData &buffers ); + //! @brief This function setups 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_d &buffers ); + //! @brief This function writes out the group data //! @param [in] dataIndex data block index given by the NewData3D //! @param [in] groupCount size of each of the buffers given diff --git a/src/E57SimpleReader.cpp b/src/E57SimpleReader.cpp index 8967fd2..b2ca220 100644 --- a/src/E57SimpleReader.cpp +++ b/src/E57SimpleReader.cpp @@ -122,4 +122,10 @@ namespace e57 return impl_->SetUpData3DPointsData( dataIndex, pointCount, buffers ); } + CompressedVectorReader Reader::SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, + const Data3DPointsData_d &buffers ) const + { + return impl_->SetUpData3DPointsData( dataIndex, pointCount, buffers ); + } + } // end namespace e57 diff --git a/src/E57SimpleWriter.cpp b/src/E57SimpleWriter.cpp index 27cd181..c2c1fa7 100644 --- a/src/E57SimpleWriter.cpp +++ b/src/E57SimpleWriter.cpp @@ -88,6 +88,12 @@ namespace e57 return impl_->SetUpData3DPointsData( dataIndex, pointCount, buffers ); } + CompressedVectorWriter Writer::SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, + const Data3DPointsData_d &buffers ) + { + return impl_->SetUpData3DPointsData( dataIndex, pointCount, buffers ); + } + bool Writer::WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue, int64_t *startPointIndex, int64_t *pointCount ) { diff --git a/src/ReaderImpl.cpp b/src/ReaderImpl.cpp index 7097a22..9802f48 100644 --- a/src/ReaderImpl.cpp +++ b/src/ReaderImpl.cpp @@ -1280,8 +1280,9 @@ namespace e57 return true; } + template CompressedVectorReader ReaderImpl::SetUpData3DPointsData( int64_t dataIndex, size_t count, - const Data3DPointsData &buffers ) const + const Data3DPointsData_t &buffers ) const { StructureNode scan( data3D_.get( dataIndex ) ); CompressedVectorNode points( scan.get( "points" ) ); @@ -1423,4 +1424,11 @@ namespace e57 return reader; } + // Explicit template instantiation + template CompressedVectorReader ReaderImpl::SetUpData3DPointsData( + int64_t dataIndex, size_t pointCount, const Data3DPointsData_t &buffers ) const; + + template CompressedVectorReader ReaderImpl::SetUpData3DPointsData( + int64_t dataIndex, size_t pointCount, const Data3DPointsData_t &buffers ) const; + } // end namespace e57 diff --git a/src/ReaderImpl.h b/src/ReaderImpl.h index 2c46e39..e2faf3f 100644 --- a/src/ReaderImpl.h +++ b/src/ReaderImpl.h @@ -67,8 +67,9 @@ namespace e57 bool ReadData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue, int64_t *startPointIndex, int64_t *pointCount ) const; + template CompressedVectorReader SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, - const Data3DPointsData &buffers ) const; + const Data3DPointsData_t &buffers ) const; StructureNode GetRawE57Root() const; diff --git a/src/WriterImpl.cpp b/src/WriterImpl.cpp index 8f92dae..4e94acb 100644 --- a/src/WriterImpl.cpp +++ b/src/WriterImpl.cpp @@ -941,8 +941,9 @@ namespace e57 return pos; } + template CompressedVectorWriter WriterImpl::SetUpData3DPointsData( int64_t dataIndex, size_t count, - const Data3DPointsData &buffers ) + const Data3DPointsData_t &buffers ) { StructureNode scan( data3D_.get( dataIndex ) ); CompressedVectorNode points( scan.get( "points" ) ); @@ -1061,6 +1062,13 @@ namespace e57 return writer; } + // Explicit template instantiation + template CompressedVectorWriter WriterImpl::SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, + const Data3DPointsData_t &buffers ); + + template CompressedVectorWriter WriterImpl::SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, + const Data3DPointsData_t &buffers ); + // This funtion writes out the group data bool WriterImpl::WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue, int64_t *startPointIndex, int64_t *pointCount ) diff --git a/src/WriterImpl.h b/src/WriterImpl.h index 99209fb..b0e7d92 100644 --- a/src/WriterImpl.h +++ b/src/WriterImpl.h @@ -51,8 +51,9 @@ namespace e57 int64_t NewData3D( Data3D &data3DHeader ); + template CompressedVectorWriter SetUpData3DPointsData( int64_t dataIndex, size_t pointCount, - const Data3DPointsData &buffers ); + const Data3DPointsData_t &buffers ); bool WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue, int64_t *startPointIndex, int64_t *pointCount );