Code review, brush-up, and extended surface unit tests

This commit is contained in:
Stein Inge Dale
2020-06-03 13:34:18 +02:00
committed by Magne Sjaastad
parent e5f3a3b67d
commit 10e4c60073
5 changed files with 66 additions and 24 deletions

View File

@@ -19,9 +19,11 @@
#include "RifSurfaceReader.h"
#include "RigGocadData.h"
#include "cvfAssert.h"
#include "cvfVector3.h"
#include "QStringList"
#include <fstream>
#include <limits>
#include <map>
@@ -37,6 +39,8 @@
//--------------------------------------------------------------------------------------------------
void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* gocadData )
{
CVF_ASSERT( gocadData );
enum class GocadZPositive
{
Elevation,
@@ -50,7 +54,6 @@ void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* goc
std::vector<QString> propertyNames;
std::vector<std::vector<float>> propertyValues;
size_t propertyRow = 0;
{
std::ifstream stream( filename.toLatin1().data() );
@@ -110,13 +113,14 @@ void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* goc
vertexIdToIndex[vertexId] = static_cast<unsigned>( vertices.size() - 1 );
}
propertyValues.push_back( std::vector<float>( propertyNames.size() ) );
for ( size_t i = 0; i < propertyNames.size(); i++ )
{
lineStream >> propertyValues[propertyRow][i];
float value = std::numeric_limits<double>::infinity();
lineStream >> value;
propertyValues[i].push_back( value );
}
propertyRow++;
}
else if ( firstToken.compare( "TRGL" ) == 0 )
{
@@ -154,6 +158,8 @@ void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* goc
{
propertyNames.push_back( w );
}
propertyValues.resize( propertyNames.size() );
}
else if ( firstToken.compare( "ZPOSITIVE" ) == 0 )
{
@@ -184,8 +190,11 @@ void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* goc
}
}
gocadData->setGeometryData( vertices, triangleIndices );
gocadData->addPropertyData( propertyNames, propertyValues );
if ( gocadData )
{
gocadData->setGeometryData( vertices, triangleIndices );
gocadData->addPropertyData( propertyNames, propertyValues );
}
}
//--------------------------------------------------------------------------------------------------

View File

@@ -38,6 +38,8 @@ RimFileSurface::RimFileSurface()
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_surfaceDefinitionFilePath, "SurfaceFilePath", "File", "", "", "" );
m_gocadData.reset( new RigGocadData );
}
//--------------------------------------------------------------------------------------------------
@@ -147,10 +149,9 @@ bool RimFileSurface::loadDataFromFile()
}
else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) )
{
RigGocadData gocadData;
RifSurfaceReader::readGocadFile( filePath, &gocadData );
RifSurfaceReader::readGocadFile( filePath, m_gocadData.get() );
surface = gocadData.gocadGeometry();
surface = m_gocadData->gocadGeometry();
}
m_vertices = surface.first;

View File

@@ -20,6 +20,10 @@
#include "RimSurface.h"
#include <memory>
class RigGocadData;
class RimFileSurface : public RimSurface
{
CAF_PDM_HEADER_INIT;
@@ -45,4 +49,6 @@ private:
std::vector<unsigned> m_tringleIndices;
std::vector<cvf::Vec3d> m_vertices;
std::unique_ptr<RigGocadData> m_gocadData;
};

View File

@@ -53,23 +53,15 @@ std::pair<std::vector<cvf::Vec3d>, std::vector<unsigned>> RigGocadData::gocadGeo
//--------------------------------------------------------------------------------------------------
std::vector<float> RigGocadData::propertyValues( const QString& property )
{
size_t propertyIdx = 0;
for ( propertyIdx = 0; propertyIdx < m_propertyNames.size(); propertyIdx++ )
for ( size_t propertyIdx = 0; propertyIdx < m_propertyNames.size(); propertyIdx++ )
{
if ( m_propertyNames[propertyIdx] == property ) break;
if ( m_propertyNames[propertyIdx] == property )
{
return m_propertyValues[propertyIdx];
}
}
std::vector<float> propValues;
propValues.reserve( m_propertyValues.size() );
for ( size_t i = 0; i < m_propertyValues.size(); i++ )
{
propValues.push_back( m_propertyValues[i][propertyIdx] );
}
return propValues;
return std::vector<float>(); // return empty vector in case property was not found
}
//--------------------------------------------------------------------------------------------------

View File

@@ -91,6 +91,40 @@ TEST( RifSurfaceReader, GocadReadProperties )
EXPECT_NEAR( 0.010476, SY_last, 1e-4 );
}
TEST( RifSurfaceReader, GocadReadNoProperty )
{
QDir baseFolder( TEST_DATA_DIR );
QString filename( "RifSurfaceReader/tsurf_eks.ts" );
QString filePath = baseFolder.absoluteFilePath( filename );
EXPECT_TRUE( QFile::exists( filePath ) );
RigGocadData gocadData;
RifSurfaceReader::readGocadFile( filePath, &gocadData );
std::vector<QString> propNames = gocadData.propertyNames();
std::vector<float> propValues = gocadData.propertyValues( "" );
EXPECT_TRUE( propNames.size() == 0 );
EXPECT_TRUE( propValues.size() == 0 );
}
TEST( RifSurfaceReader, GocadReadNonExistingProperty )
{
QDir baseFolder( TEST_DATA_DIR );
QString filename( "RifSurfaceReader/geom_with_properties.ts" );
QString filePath = baseFolder.absoluteFilePath( filename );
EXPECT_TRUE( QFile::exists( filePath ) );
RigGocadData gocadData;
RifSurfaceReader::readGocadFile( filePath, &gocadData );
std::vector<float> propValues = gocadData.propertyValues( "NonExistingProperty" );
EXPECT_TRUE( propValues.size() == 0 );
}
TEST( RifSurfaceReader, ReadWrongFileType )
{
QDir baseFolder( TEST_DATA_DIR );