From 9a0f06234c658cffa51fc5d4adcf43c1675c5f55 Mon Sep 17 00:00:00 2001 From: Andrew Bell Date: Fri, 31 May 2019 12:16:15 -0400 Subject: [PATCH] Revert "Test fixes." This reverts commit 0c62ab0d3c254ecb4ddfe30b7d321c4dbd11ddfb. --- plugins/e57/io/E57Reader.cpp | 286 ++++++++++++++--------------- test/unit/SpatialReferenceTest.cpp | 27 ++- 2 files changed, 156 insertions(+), 157 deletions(-) diff --git a/plugins/e57/io/E57Reader.cpp b/plugins/e57/io/E57Reader.cpp index 42710c8f3b..8aaff61f3f 100644 --- a/plugins/e57/io/E57Reader.cpp +++ b/plugins/e57/io/E57Reader.cpp @@ -51,14 +51,14 @@ m_startIndex(0), m_maxPointRead(maxPointRead), m_defaultChunkSize(1e6), m_scan(s for (auto& dimension: e57Dimensions) m_doubleBuffers[dimension] = std::vector(m_defaultChunkSize,0); - auto vectorNode = scan->getPoints(); + auto vectorNode = scan->getPoints(); auto prototype = static_cast(vectorNode.prototype()); for (auto& keyValue: m_doubleBuffers) m_e57buffers.emplace_back(vectorNode.destImageFile(), keyValue.first, keyValue.second.data(), m_defaultChunkSize, true, (prototype.get(keyValue.first).type() == e57::E57_SCALED_INTEGER) ); - m_pointOffset = pointOffset; + m_pointOffset = pointOffset; // Setup the reader m_dataReader = std::unique_ptr( @@ -67,19 +67,19 @@ m_startIndex(0), m_maxPointRead(maxPointRead), m_defaultChunkSize(1e6), m_scan(s E57Reader::ChunkReader::~ChunkReader() { - if (m_dataReader) - m_dataReader->close(); + if (m_dataReader) + m_dataReader->close(); } bool E57Reader::ChunkReader::isInScope(pdal::point_count_t index) const { - pdal::point_count_t actualIndex = index - m_pointOffset; - return (actualIndex>=0 && actualIndex < m_maxPointRead); + pdal::point_count_t actualIndex = index - m_pointOffset; + return (actualIndex>=0 && actualIndex < m_maxPointRead); } bool E57Reader::ChunkReader::isInChunk(pdal::point_count_t index) const { - pdal::point_count_t actualIndex = index - m_pointOffset; + pdal::point_count_t actualIndex = index - m_pointOffset; if (actualIndex < m_startIndex) throw std::out_of_range("E57 reader tries to go back in the data. Not allowed."); @@ -89,38 +89,38 @@ bool E57Reader::ChunkReader::isInChunk(pdal::point_count_t index) const void E57Reader::ChunkReader::setPoint (pdal::point_count_t pointIndex, pdal::PointRef point, const std::set& e57Dimensions) const { - pdal::point_count_t actualIndex = pointIndex - m_pointOffset; + pdal::point_count_t actualIndex = pointIndex - m_pointOffset; pdal::point_count_t index = actualIndex - m_startIndex; - // Sets values from buffer arrays for each dimension in the scan + // Sets values from buffer arrays for each dimension in the scan for (auto& keyValue: m_doubleBuffers) { - auto pdalDimension = pdal::e57plugin::e57ToPdal(keyValue.first); - if (pdalDimension != pdal::Dimension::Id::Unknown) + auto pdalDimension = pdal::e57plugin::e57ToPdal(keyValue.first); + if (pdalDimension != pdal::Dimension::Id::Unknown) { - double value; - // Rescale the value if needed so that if fits Pdal expectations - try - { - auto minmax = m_scan->getLimits(pdalDimension); - value = pdal::e57plugin::rescaleE57ToPdalValue(keyValue.first,keyValue.second[index],minmax); - } + double value; + // Rescale the value if needed so that if fits Pdal expectations + try + { + auto minmax = m_scan->getLimits(pdalDimension); + value = pdal::e57plugin::rescaleE57ToPdalValue(keyValue.first,keyValue.second[index],minmax); + } catch (std::out_of_range &e) - { - value = keyValue.second[index]; - } - point.setField(pdalDimension,value); - } + { + value = keyValue.second[index]; + } + point.setField(pdalDimension,value); + } } - // Applies pose transformation if needed - if (m_scan->hasPose()) - m_scan->transformPoint(point); + // Applies pose transformation if needed + if (m_scan->hasPose()) + m_scan->transformPoint(point); } pdal::point_count_t E57Reader::ChunkReader::read(pdal::point_count_t index) { - pdal::point_count_t actualIndex = index - m_pointOffset; + pdal::point_count_t actualIndex = index - m_pointOffset; m_startIndex = actualIndex; return m_dataReader->read(); } @@ -129,219 +129,219 @@ pdal::point_count_t E57Reader::ChunkReader::read(pdal::point_count_t index) static PluginInfo const s_info { - "readers.e57", - "E57 Reader", - "http://libe57.org/" + "readers.e57", + "E57 Reader", + "http://libe57.org/" }; CREATE_SHARED_STAGE(E57Reader, s_info) E57Reader::~E57Reader() { - if (m_imf) - m_imf->close(); + if (m_imf) + m_imf->close(); } E57Reader::E57Reader(std::string filename) : Reader(), Streamable(), m_currentPoint(0), m_pointCount(0) { - m_filenameManual = filename; - initialize(); + m_filenameManual = filename; + initialize(); } std::string E57Reader::getName() const { - return s_info.name; + return s_info.name; } -void E57Reader::initialize() +void E57Reader::initialize() { if (m_filename.empty()) - m_filename = m_filenameManual; + m_filename = m_filenameManual; openFile(m_filename); extractScans(); - m_pointCount = extractNumberPoints(); - m_chunk = std::unique_ptr(nullptr); - m_currentPoint = 0; + m_pointCount = extractNumberPoints(); + m_chunk = std::unique_ptr(nullptr); + m_currentPoint = 0; } void E57Reader::addDimensions(PointLayoutPtr layout) { - std::set supportedDimensions; + std::set supportedDimensions; if (m_scans.empty()) - return; - - auto commonDimensions = getDimensions(); - for (auto& dim: commonDimensions) - { - auto pdalDimension = pdal::e57plugin::e57ToPdal(dim); - if (pdalDimension != pdal::Dimension::Id::Unknown) - layout->registerDim(pdalDimension); - } + return; + + auto commonDimensions = getDimensions(); + for (auto& dim: commonDimensions) + { + auto pdalDimension = pdal::e57plugin::e57ToPdal(dim); + if (pdalDimension != pdal::Dimension::Id::Unknown) + layout->registerDim(pdalDimension); + } } point_count_t E57Reader::read(PointViewPtr view, point_count_t count) { - // How many do we read - PointId nextId = view->size(); - point_count_t remainingInput = m_pointCount - nextId; - point_count_t toReadCount = std::min(count, remainingInput); + // How many do we read + PointId nextId = view->size(); + point_count_t remainingInput = m_pointCount - nextId; + point_count_t toReadCount = std::min(count, remainingInput); - point_count_t remaining = toReadCount; + point_count_t remaining = toReadCount; for (point_count_t i=0; i < remaining; i++) { PointRef point(view->point(nextId)); - m_currentPoint = nextId; + m_currentPoint = nextId; processOne(point); nextId++; } - // Return what was read + // Return what was read return toReadCount; } bool E57Reader::processOne(pdal::PointRef& point) { - // Did we go too far? - if (m_currentPoint >= m_pointCount) + // Did we go too far? + if (m_currentPoint >= m_pointCount) return false; - // Are we not in the same scan? - if (!m_chunk || !m_chunk->isInScope(m_currentPoint)) - { - // setup new reader + // Are we not in the same scan? + if (!m_chunk || !m_chunk->isInScope(m_currentPoint)) + { + // setup new reader setupReader(m_currentPoint); - m_chunk->read(m_currentPoint); - } + m_chunk->read(m_currentPoint); + } if (!m_chunk->isInChunk(m_currentPoint)) m_chunk->read(m_currentPoint); m_chunk->setPoint(m_currentPoint,point, getDimensions()); - m_currentPoint++; - return true; + m_currentPoint++; + return true; } std::vector> E57Reader::getScans() const { - return m_scans; + return m_scans; } int E57Reader::getScanIndex(pdal::point_count_t pointIndex) const { - if (pointIndex > m_pointCount) - return -1; - - pdal::point_count_t counter = 0; - for (pdal::point_count_t i=0; i < m_scans.size(); i++) - { - counter += m_scans[i]->getNumPoints(); - if (pointIndex m_pointCount) + return -1; + + pdal::point_count_t counter = 0; + for (pdal::point_count_t i=0; i < m_scans.size(); i++) + { + counter += m_scans[i]->getNumPoints(); + if (pointIndex E57Reader::getDimensions() { - if (!m_validDimensions.empty()) - return m_validDimensions; + if (!m_validDimensions.empty()) + return m_validDimensions; // Extract smallest common denominator across all scans - auto commonDimensions = m_scans[0]->getDimensions(); - std::vector dimensionsToRemove; + auto commonDimensions = m_scans[0]->getDimensions(); + std::vector dimensionsToRemove; for (auto &scan: m_scans) - { - auto newDims = scan->getDimensions(); + { + auto newDims = scan->getDimensions(); for (auto &dim: commonDimensions) - { - if (newDims.find(dim) == newDims.end()) - dimensionsToRemove.push_back(dim); - } - } + { + if (newDims.find(dim) == newDims.end()) + dimensionsToRemove.push_back(dim); + } + } for (auto &dim: dimensionsToRemove) - commonDimensions.erase(dim); + commonDimensions.erase(dim); - m_validDimensions = commonDimensions; - return m_validDimensions; + m_validDimensions = commonDimensions; + return m_validDimensions; } -pdal::point_count_t E57Reader::getNumberPoints() const +pdal::point_count_t E57Reader::getNumberPoints() const { - return m_pointCount; + return m_pointCount; } void E57Reader::openFile(const std::string &filename) { - try - { - m_imf = std::unique_ptr(new e57::ImageFile(filename,"r",e57::CHECKSUM_POLICY_SPARSE)); - if (!m_imf->isOpen()) + try + { + m_imf = std::unique_ptr(new e57::ImageFile(filename,"r",e57::CHECKSUM_POLICY_SPARSE)); + if (!m_imf->isOpen()) throwError("Failed opening the file : " + filename); - const e57::ustring normalsExtension("http://www.libe57.org/E57_NOR_surface_normals.txt"); - e57::ustring _normalsExtension; - if (!m_imf->extensionsLookupPrefix("nor", _normalsExtension)) //the extension may already be registered - m_imf->extensionsAdd("nor", normalsExtension); - } - catch(const e57::E57Exception& e) - { + const e57::ustring normalsExtension("http://www.libe57.org/E57_NOR_surface_normals.txt"); + e57::ustring _normalsExtension; + if (!m_imf->extensionsLookupPrefix("nor", _normalsExtension)) //the extension may already be registered + m_imf->extensionsAdd("nor", normalsExtension); + } + catch(const e57::E57Exception& e) + { throwError("E57 error with code " + std::to_string(e.errorCode()) + " : " + e.context()); - } - catch(...) - { + } + catch(...) + { std::string msg("Unknown error in E57 plugin"); throwError(msg); - } + } } void E57Reader::setupReader(pdal::point_count_t pointNumber) { - int currentScan = getScanIndex(pointNumber); - if (currentScan == -1) - throw std::out_of_range("Something went wrong in processing a point"); - - pdal::point_count_t offset = 0; - pdal::point_count_t maxRead = m_scans[0]->getNumPoints(); - for (int i=1; i<=currentScan; i++) - { - maxRead = m_scans[i]->getNumPoints(); - offset += m_scans[i-1]->getNumPoints(); - } - - m_chunk.reset(); - auto pointNode = m_scans[currentScan]->getPoints(); - m_chunk = std::unique_ptr(new ChunkReader(offset,maxRead,m_scans[currentScan],getDimensions())); + int currentScan = getScanIndex(pointNumber); + if (currentScan == -1) + throw std::out_of_range("Something went wrong in processing a point"); + + pdal::point_count_t offset = 0; + pdal::point_count_t maxRead = m_scans[0]->getNumPoints(); + for (int i=1; i<=currentScan; i++) + { + maxRead = m_scans[i]->getNumPoints(); + offset += m_scans[i-1]->getNumPoints(); + } + + m_chunk.reset(); + auto pointNode = m_scans[currentScan]->getPoints(); + m_chunk = std::unique_ptr(new ChunkReader(offset,maxRead,m_scans[currentScan],getDimensions())); } pdal::point_count_t E57Reader::extractNumberPoints() const { - pdal::point_count_t count = 0; - for (auto& scan: m_scans) - count += scan->getNumPoints(); + pdal::point_count_t count = 0; + for (auto& scan: m_scans) + count += scan->getNumPoints(); - return count; + return count; } void E57Reader::extractScans() { - e57::StructureNode root = m_imf->root(); - if (!root.isDefined("/data3D")) - throw std::invalid_argument("File does not contain valid 3D data"); + e57::StructureNode root = m_imf->root(); + if (!root.isDefined("/data3D")) + throw std::invalid_argument("File does not contain valid 3D data"); //E57 standard: "data3D is a vector for storing an arbitrary number of 3D data sets " e57::VectorNode n(root.get("/data3D")); - for (unsigned i = 0; i < n.childCount(); i++) - { - try { - e57::StructureNode scanNode(n.get(i)); - m_scans.emplace_back(new e57::Scan(scanNode)); - } - catch (const std::exception& e) - { + for (unsigned i = 0; i < n.childCount(); i++) + { + try { + e57::StructureNode scanNode(n.get(i)); + m_scans.emplace_back(new e57::Scan(scanNode)); + } + catch (const std::exception& e) + { throwError(std::string("Failed to extract scans from the E57 file: ") + e.what()); - } - } -} + } + } } +} \ No newline at end of file diff --git a/test/unit/SpatialReferenceTest.cpp b/test/unit/SpatialReferenceTest.cpp index 8416f54574..b62947b3f1 100644 --- a/test/unit/SpatialReferenceTest.cpp +++ b/test/unit/SpatialReferenceTest.cpp @@ -96,16 +96,17 @@ TEST(SpatialReferenceTest, test_proj4_roundtrip) TEST(SpatialReferenceTest, test_userstring_roundtrip) { std::string code = "EPSG:4326"; + std::string proj4 = "+proj=longlat +datum=WGS84 +no_defs"; + std::string proj4_ellps = + "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"; + const std::string wkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; SpatialReference ref(code); std::string ret_proj = ref.getProj4(); std::string ret_wkt = ref.getWKT(); - std::string proj4 = "+proj=longlat +datum=WGS84 +no_defs"; EXPECT_EQ(ret_proj, proj4); - - const std::string wkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]"; - EXPECT_NE(ret_wkt.find(wkt), std::string::npos); + EXPECT_EQ(ret_wkt, wkt); } @@ -233,11 +234,11 @@ TEST(SpatialReferenceTest, test_writing_vlr) { std::string tmpfile(Support::temppath("tmp_srs_9.las")); - const std::string reference_wkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]"; + const std::string reference_wkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; SpatialReference ref("EPSG:4326"); std::string wkt = ref.getWKT(); - EXPECT_NE(wkt.find(reference_wkt), std::string::npos); + EXPECT_EQ(wkt, reference_wkt); // Write a very simple file with our SRS and one point. { @@ -277,7 +278,7 @@ TEST(SpatialReferenceTest, test_writing_vlr) EXPECT_EQ(reader.header().vlrCount(), 2u); std::string wkt = result_ref.getWKT(); - EXPECT_NE(wkt.find(reference_wkt), std::string::npos); + EXPECT_EQ(wkt, reference_wkt); } // Cleanup @@ -307,16 +308,14 @@ TEST(SpatialReferenceTest, test_vertical_and_horizontal) const std::string wkt = "COMPD_CS[\"WGS 84 + VERT_CS\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],VERT_CS[\"NAVD88 height\",VERT_DATUM[\"North American Vertical Datum 1988\",2005,AUTHORITY[\"EPSG\",\"5103\"],EXTENSION[\"PROJ4_GRIDS\",\"g2003conus.gtx\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Up\",UP],AUTHORITY[\"EPSG\",\"5703\"]]]"; SpatialReference srs(wkt); - std::string horiz = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]"; + std::string horiz = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; + std::string vert = "VERT_CS[\"NAVD88 height\",VERT_DATUM[\"North American Vertical Datum 1988\",2005,AUTHORITY[\"EPSG\",\"5103\"],EXTENSION[\"PROJ4_GRIDS\",\"g2003conus.gtx\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Up\",UP],AUTHORITY[\"EPSG\",\"5703\"]]"; std::string horizontal = srs.getHorizontal(); - EXPECT_NE(horizontal.find(horiz), std::string::npos); - std::string vertical = srs.getVertical(); - std::vector vertRef { { - "VERT_CS[\"NAVD88 height\",VERT_DATUM[\"North American Vertical Datum 1988\",2005,AUTHORITY[\"EPSG\",\"5103\"],EXTENSION[\"PROJ4_GRIDS\",\"g2003conus.gtx\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Up\",UP],AUTHORITY[\"EPSG\",\"5703\"]]", - "VERT_CS[\"NAVD88 height\",VERT_DATUM[\"North American Vertical Datum 1988\",2005,AUTHORITY[\"EPSG\",\"5103\"],EXTENSION[\"PROJ4_GRIDS\",\"g2003conus.gtx\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Up\",UP],AUTHORITY[\"EPSG\",\"5703\"]]" } }; - EXPECT_TRUE(Utils::contains(vertRef, vertical)); + EXPECT_EQ(horiz, horizontal); + EXPECT_EQ(vert, vertical); + } TEST(SpatialReferenceTest, readerOptions)