mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Code review, brush-up, and extended surface unit tests
This commit is contained in:
committed by
Magne Sjaastad
parent
e5f3a3b67d
commit
10e4c60073
@@ -19,9 +19,11 @@
|
|||||||
#include "RifSurfaceReader.h"
|
#include "RifSurfaceReader.h"
|
||||||
#include "RigGocadData.h"
|
#include "RigGocadData.h"
|
||||||
|
|
||||||
|
#include "cvfAssert.h"
|
||||||
#include "cvfVector3.h"
|
#include "cvfVector3.h"
|
||||||
|
|
||||||
#include "QStringList"
|
#include "QStringList"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -37,6 +39,8 @@
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* gocadData )
|
void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* gocadData )
|
||||||
{
|
{
|
||||||
|
CVF_ASSERT( gocadData );
|
||||||
|
|
||||||
enum class GocadZPositive
|
enum class GocadZPositive
|
||||||
{
|
{
|
||||||
Elevation,
|
Elevation,
|
||||||
@@ -50,7 +54,6 @@ void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* goc
|
|||||||
|
|
||||||
std::vector<QString> propertyNames;
|
std::vector<QString> propertyNames;
|
||||||
std::vector<std::vector<float>> propertyValues;
|
std::vector<std::vector<float>> propertyValues;
|
||||||
size_t propertyRow = 0;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::ifstream stream( filename.toLatin1().data() );
|
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 );
|
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++ )
|
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 )
|
else if ( firstToken.compare( "TRGL" ) == 0 )
|
||||||
{
|
{
|
||||||
@@ -154,6 +158,8 @@ void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* goc
|
|||||||
{
|
{
|
||||||
propertyNames.push_back( w );
|
propertyNames.push_back( w );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
propertyValues.resize( propertyNames.size() );
|
||||||
}
|
}
|
||||||
else if ( firstToken.compare( "ZPOSITIVE" ) == 0 )
|
else if ( firstToken.compare( "ZPOSITIVE" ) == 0 )
|
||||||
{
|
{
|
||||||
@@ -184,8 +190,11 @@ void RifSurfaceReader::readGocadFile( const QString& filename, RigGocadData* goc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gocadData->setGeometryData( vertices, triangleIndices );
|
if ( gocadData )
|
||||||
gocadData->addPropertyData( propertyNames, propertyValues );
|
{
|
||||||
|
gocadData->setGeometryData( vertices, triangleIndices );
|
||||||
|
gocadData->addPropertyData( propertyNames, propertyValues );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ RimFileSurface::RimFileSurface()
|
|||||||
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
|
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
|
||||||
|
|
||||||
CAF_PDM_InitFieldNoDefault( &m_surfaceDefinitionFilePath, "SurfaceFilePath", "File", "", "", "" );
|
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 ) )
|
else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) )
|
||||||
{
|
{
|
||||||
RigGocadData gocadData;
|
RifSurfaceReader::readGocadFile( filePath, m_gocadData.get() );
|
||||||
RifSurfaceReader::readGocadFile( filePath, &gocadData );
|
|
||||||
|
|
||||||
surface = gocadData.gocadGeometry();
|
surface = m_gocadData->gocadGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vertices = surface.first;
|
m_vertices = surface.first;
|
||||||
|
|||||||
@@ -20,6 +20,10 @@
|
|||||||
|
|
||||||
#include "RimSurface.h"
|
#include "RimSurface.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class RigGocadData;
|
||||||
|
|
||||||
class RimFileSurface : public RimSurface
|
class RimFileSurface : public RimSurface
|
||||||
{
|
{
|
||||||
CAF_PDM_HEADER_INIT;
|
CAF_PDM_HEADER_INIT;
|
||||||
@@ -45,4 +49,6 @@ private:
|
|||||||
|
|
||||||
std::vector<unsigned> m_tringleIndices;
|
std::vector<unsigned> m_tringleIndices;
|
||||||
std::vector<cvf::Vec3d> m_vertices;
|
std::vector<cvf::Vec3d> m_vertices;
|
||||||
|
|
||||||
|
std::unique_ptr<RigGocadData> m_gocadData;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,23 +53,15 @@ std::pair<std::vector<cvf::Vec3d>, std::vector<unsigned>> RigGocadData::gocadGeo
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
std::vector<float> RigGocadData::propertyValues( const QString& property )
|
std::vector<float> RigGocadData::propertyValues( const QString& property )
|
||||||
{
|
{
|
||||||
size_t propertyIdx = 0;
|
for ( size_t propertyIdx = 0; propertyIdx < m_propertyNames.size(); propertyIdx++ )
|
||||||
|
|
||||||
for ( 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;
|
return std::vector<float>(); // return empty vector in case property was not found
|
||||||
|
|
||||||
propValues.reserve( m_propertyValues.size() );
|
|
||||||
|
|
||||||
for ( size_t i = 0; i < m_propertyValues.size(); i++ )
|
|
||||||
{
|
|
||||||
propValues.push_back( m_propertyValues[i][propertyIdx] );
|
|
||||||
}
|
|
||||||
|
|
||||||
return propValues;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -91,6 +91,40 @@ TEST( RifSurfaceReader, GocadReadProperties )
|
|||||||
EXPECT_NEAR( 0.010476, SY_last, 1e-4 );
|
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 )
|
TEST( RifSurfaceReader, ReadWrongFileType )
|
||||||
{
|
{
|
||||||
QDir baseFolder( TEST_DATA_DIR );
|
QDir baseFolder( TEST_DATA_DIR );
|
||||||
|
|||||||
Reference in New Issue
Block a user