From fef7d145c40d6f464c142b91ce899a62e013846c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 12 Dec 2024 14:57:37 +0100 Subject: [PATCH] Improve performance when importing surface data --- .../FileInterface/RifSurfaceImporter.cpp | 49 ++++++------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/ApplicationLibCode/FileInterface/RifSurfaceImporter.cpp b/ApplicationLibCode/FileInterface/RifSurfaceImporter.cpp index 6e107645e8..c1b63ba76a 100644 --- a/ApplicationLibCode/FileInterface/RifSurfaceImporter.cpp +++ b/ApplicationLibCode/FileInterface/RifSurfaceImporter.cpp @@ -411,49 +411,32 @@ std::pair, std::vector> RifSurfaceImporter::re { std::string line; std::getline( stream, line ); - std::istringstream lineStream( line ); + + auto tokens = RiaStdStringTools::splitString( line, ' ' ); + + if ( tokens.size() < 3 ) continue; double x( std::numeric_limits::infinity() ); double y( std::numeric_limits::infinity() ); double z( std::numeric_limits::infinity() ); - std::vector values; + if ( !RiaStdStringTools::toDouble( tokens[0], x ) ) continue; + if ( !RiaStdStringTools::toDouble( tokens[1], y ) ) continue; + if ( !RiaStdStringTools::toDouble( tokens[2], z ) ) continue; - // First check if we can read all numbers - bool ok = true; - lineStream >> x; - ok &= lineStream.good(); - lineStream >> y; - ok &= lineStream.good(); - lineStream >> z; - ok &= lineStream.good() || lineStream.eof(); - if ( ok ) // If we can, assume this line is a surface point + if ( x != std::numeric_limits::infinity() && y != std::numeric_limits::infinity() && + z != std::numeric_limits::infinity() ) { - if ( x != std::numeric_limits::infinity() && y != std::numeric_limits::infinity() && - z != std::numeric_limits::infinity() ) - { - // Check for extra data - while ( lineStream.good() ) - { - double d; - lineStream >> d; - if ( lineStream.good() ) values.push_back( d ); - } + // Z should be given in negative values, switch sign if positive + if ( z > 0.0 ) z = -z; - // Z should be given in negative values, switch sign if positive - if ( z > 0.0 ) z = -z; + // Add point + surfacePoints.push_back( { x, y, z } ); - // Add point - surfacePoints.push_back( { x, y, z } ); - - if ( surfacePoints.size() > 1 ) - { - cvf::Vec3d pointToPointVector = surfacePoints.back() - surfacePoints[surfacePoints.size() - 2]; - maybeInsertAxisVectorCandidate( to2d( pointToPointVector ), axesVectorCandidates, axesVectorCandidatesNum ); - } - } - else // Probably a comment line, skip + if ( surfacePoints.size() > 1 ) { + cvf::Vec3d pointToPointVector = surfacePoints.back() - surfacePoints[surfacePoints.size() - 2]; + maybeInsertAxisVectorCandidate( to2d( pointToPointVector ), axesVectorCandidates, axesVectorCandidatesNum ); } }