Refactor: simplify VTK surface parsing using pugixml

This commit is contained in:
Kristian Bendiksen committed 2025-03-07 10:34:48 +01:00
1 parent c66f4f8158
commit 7908c8186f
18 files changed
+282 -330

No files matched your search

@@ -25,8 +25,8 @@
#include "RifSurfaceImporter.h"
#include "RifVtkSurfaceImporter.h"
#include "RigGocadData.h"
#include "RigSurface.h"
#include "RigTriangleMeshData.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
@@ -135,12 +135,12 @@ bool RimFileSurface::updateSurfaceData()
surface->setTriangleData( tringleIndices, vertices );
}
if ( m_gocadData )
if ( m_triangleMeshData )
{
auto propertyNames = m_gocadData->propertyNames();
auto propertyNames = m_triangleMeshData->propertyNames();
for ( const auto& name : propertyNames )
{
auto values = m_gocadData->propertyValues( name );
auto values = m_triangleMeshData->propertyValues( name );
surface->addVerticeResult( name, values );
}
}
@@ -173,18 +173,17 @@ bool RimFileSurface::loadDataFromFile()
}
else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) )
{
m_gocadData = std::make_unique<RigGocadData>();
m_triangleMeshData = std::make_unique<RigTriangleMeshData>();
RifSurfaceImporter::readGocadFile( filePath, m_gocadData.get() );
RifSurfaceImporter::readGocadFile( filePath, m_triangleMeshData.get() );
surface = m_gocadData->gocadGeometry();
surface = m_triangleMeshData->geometry();
}
else if ( filePath.endsWith( "vtu", Qt::CaseInsensitive ) )
{
m_gocadData = std::make_unique<RigGocadData>();
RifVtkSurfaceImporter::importFromFile( filePath.toStdString(), m_gocadData.get() );
m_triangleMeshData = RifVtkSurfaceImporter::importFromFile( filePath.toStdString() );
surface = m_gocadData->gocadGeometry();
surface = m_triangleMeshData->geometry();
}
else if ( filePath.endsWith( "dat", Qt::CaseInsensitive ) || filePath.endsWith( "xyz", Qt::CaseInsensitive ) )
{
@@ -22,7 +22,7 @@
#include <memory>
class RigGocadData;
class RigTriangleMeshData;
class RimFileSurface : public RimSurface
{
@@ -53,5 +53,5 @@ private:
std::vector<unsigned> m_tringleIndices;
std::vector<cvf::Vec3d> m_vertices;
std::unique_ptr<RigGocadData> m_gocadData;
std::unique_ptr<RigTriangleMeshData> m_triangleMeshData;
};
@@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- Equinor ASA
// Copyright (C) 2025- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -18,22 +18,18 @@
#include "RimFractureSurface.h"
#include "RiaPreferences.h"
#include "RigStatisticsMath.h"
#include "RigSurface.h"
#include "RigTriangleMeshData.h"
#include "RimRegularLegendConfig.h"
#include "RimSurfaceCollection.h"
#include "RifSurfaceImporter.h"
#include "RifVtkSurfaceImporter.h"
#include "RigGocadData.h"
#include "RigSurface.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
#include <QFileInfo>
#include <memory>
CAF_PDM_SOURCE_INIT( RimFractureSurface, "RimFractureSurface" );
//--------------------------------------------------------------------------------------------------
@@ -108,14 +104,14 @@ void RimFractureSurface::loadSurfaceDataForTimeStep( int timeStep )
auto surface = new RigSurface;
auto gocadData = m_surfacePerTimeStep[timeStep];
const auto& [coordinates, indices] = gocadData.gocadGeometry();
auto triangleMeshData = m_surfacePerTimeStep[timeStep].get();
const auto& [coordinates, indices] = triangleMeshData->geometry();
surface->setTriangleData( indices, coordinates );
auto propertyNames = gocadData.propertyNames();
auto propertyNames = triangleMeshData->propertyNames();
for ( const auto& name : propertyNames )
{
auto values = gocadData.propertyValues( name );
auto values = triangleMeshData->propertyValues( name );
surface->addVerticeResult( name, values );
}
setSurfaceData( surface );
@@ -127,11 +123,11 @@ void RimFractureSurface::loadSurfaceDataForTimeStep( int timeStep )
std::vector<std::vector<double>> RimFractureSurface::valuesForProperty( const QString& propertyName ) const
{
std::vector<std::vector<double>> values;
for ( auto allTimeStepValues : m_surfacePerTimeStep )
for ( const auto& allTimeStepValues : m_surfacePerTimeStep )
{
const auto& [coordinates, indices] = allTimeStepValues.gocadGeometry();
const auto& [coordinates, indices] = allTimeStepValues->geometry();
auto valuesOneTimeStep = allTimeStepValues.propertyValues( propertyName );
auto valuesOneTimeStep = allTimeStepValues->propertyValues( propertyName );
// convert to double vector
std::vector<double> valuesOneTimeStepDouble( valuesOneTimeStep.begin(), valuesOneTimeStep.end() );
@@ -178,11 +174,6 @@ void RimFractureSurface::clearCachedNativeData()
{
m_secondsSinceSimulationStart.clear();
m_surfacePerTimeStep.clear();
/*
m_vertices.clear();
m_tringleIndices.clear();
*/
}
//--------------------------------------------------------------------------------------------------
@@ -190,17 +181,61 @@ void RimFractureSurface::clearCachedNativeData()
//--------------------------------------------------------------------------------------------------
bool RimFractureSurface::loadDataFromFile()
{
auto surfaceInfo = RifVtkSurfaceImporter::parsePvdDatasets( m_surfaceDefinitionFilePath().path().toStdString() );
std::filesystem::path filepath = m_surfaceDefinitionFilePath().path().toLocal8Bit().constData();
auto surfaceInfo = RifVtkSurfaceImporter::parsePvdDatasets( filepath );
for ( const auto& s : surfaceInfo )
{
RigGocadData gocadData;
if ( RifVtkSurfaceImporter::importFromFile( s.filename, &gocadData ) )
if ( auto triangleMeshData = RifVtkSurfaceImporter::importFromFile( s.filepath ) )
{
m_secondsSinceSimulationStart.push_back( s.timestep );
m_surfacePerTimeStep.push_back( gocadData );
m_surfacePerTimeStep.push_back( std::move( triangleMeshData ) );
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFractureSurface::updateMinMaxValues( RimRegularLegendConfig* legendConfig, const QString& propertyName, int currentTimeStep ) const
{
double localMin = 0.0;
double localMax = 0.0;
double localPosClosestToZero = 0.0;
double localNegClosestToZero = 0.0;
auto valuesForTimeSteps = valuesForProperty( propertyName );
MinMaxAccumulator minMaxAccumulator;
PosNegAccumulator posNegAccumulator;
for ( size_t timeIndex = 0; timeIndex < valuesForTimeSteps.size(); timeIndex++ )
{
auto values = valuesForTimeSteps[timeIndex];
minMaxAccumulator.addData( values );
posNegAccumulator.addData( values );
if ( static_cast<int>( timeIndex ) == currentTimeStep )
{
MinMaxAccumulator localMinMaxAccumulator;
PosNegAccumulator localPosNegAccumulator;
localMinMaxAccumulator.addData( values );
localPosNegAccumulator.addData( values );
localPosClosestToZero = localPosNegAccumulator.pos;
localNegClosestToZero = localPosNegAccumulator.neg;
localMin = localMinMaxAccumulator.min;
localMax = localMinMaxAccumulator.max;
}
}
double globalPosClosestToZero = posNegAccumulator.pos;
double globalNegClosestToZero = posNegAccumulator.neg;
double globalMin = minMaxAccumulator.min;
double globalMax = minMaxAccumulator.max;
legendConfig->setClosestToZeroValues( globalPosClosestToZero, globalNegClosestToZero, localPosClosestToZero, localNegClosestToZero );
legendConfig->setAutomaticRanges( globalMin, globalMax, localMin, localMax );
}
@@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- Equinor ASA
// Copyright (C) 2025- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -20,10 +20,7 @@
#include "RimSurface.h"
#include "cafPdmChildArrayField.h"
class RimFileSurface;
class RigGocadData;
class RigTriangleMeshData;
class RimFractureSurface : public RimSurface
{
@@ -43,6 +40,8 @@ public:
std::vector<std::vector<double>> valuesForProperty( const QString& propertyName ) const;
void updateMinMaxValues( RimRegularLegendConfig* legend, const QString& propertyName, int currentTimeStep ) const override;
protected:
bool updateSurfaceData() override;
void clearCachedNativeData() override;
@@ -55,6 +54,6 @@ private:
caf::PdmField<caf::FilePath> m_surfaceDefinitionFilePath;
std::vector<size_t> m_secondsSinceSimulationStart;
std::vector<RigGocadData> m_surfacePerTimeStep;
std::vector<size_t> m_secondsSinceSimulationStart;
std::vector<std::unique_ptr<RigTriangleMeshData>> m_surfacePerTimeStep;
};
@@ -19,14 +19,15 @@
#include "RimSurface.h"
#include "RiaApplication.h"
#include "RimCase.h"
#include "RimProject.h"
#include "RimRegularLegendConfig.h"
#include "RimSurfaceCollection.h"
#include "RigStatisticsMath.h"
#include "RigSurface.h"
#include "RifSurfaceImporter.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
#include "cafPdmUiDoubleSliderEditor.h"
@@ -322,3 +323,27 @@ void RimSurface::defineEditorAttribute( const caf::PdmFieldHandle* field, QStrin
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::updateMinMaxValues( RimRegularLegendConfig* legend, const QString& propertyName, int currentTimeStep ) const
{
if ( !m_surfaceData.isNull() )
{
MinMaxAccumulator minMaxAccumulator;
PosNegAccumulator posNegAccumulator;
auto values = m_surfaceData->propertyValues( propertyName );
minMaxAccumulator.addData( values );
posNegAccumulator.addData( values );
double globalPosClosestToZero = posNegAccumulator.pos;
double globalNegClosestToZero = posNegAccumulator.neg;
double globalMin = minMaxAccumulator.min;
double globalMax = minMaxAccumulator.max;
legend->setClosestToZeroValues( globalPosClosestToZero, globalNegClosestToZero, globalPosClosestToZero, globalNegClosestToZero );
legend->setAutomaticRanges( globalMin, globalMax, globalMin, globalMax );
}
}
@@ -28,6 +28,7 @@
#include <vector>
class RimRegularLegendConfig;
class RigSurface;
class RimSurface : public caf::PdmObject
@@ -68,6 +69,8 @@ public:
void loadDataIfRequired();
void reloadData();
virtual void updateMinMaxValues( RimRegularLegendConfig* legend, const QString& propertyName, int currentTimeStep ) const;
protected:
void setSurfaceData( RigSurface* surface );
@@ -18,14 +18,11 @@
#include "RimSurfaceResultDefinition.h"
#include "RiaDefines.h"
#include "RiaResultNames.h"
#include "RigStatisticsMath.h"
#include "RigSurface.h"
#include "Rim3dView.h"
#include "RimFractureSurface.h"
#include "RimRegularLegendConfig.h"
#include "RimSurface.h"
#include "RimSurfaceInView.h"
@@ -90,82 +87,11 @@ RimRegularLegendConfig* RimSurfaceResultDefinition::legendConfig()
//--------------------------------------------------------------------------------------------------
void RimSurfaceResultDefinition::updateMinMaxValues( int currentTimeStep )
{
if ( !m_surfaceInView ) return;
if ( currentTimeStep < 0 ) currentTimeStep = 0;
// TODO: This is a hack, we need to find a better way to handle time dependent data for a surface
if ( auto fractureSurface = dynamic_cast<RimFractureSurface*>( m_surfaceInView->surface() ) )
{
double localMin = 0.0;
double localMax = 0.0;
double localPosClosestToZero = 0.0;
double localNegClosestToZero = 0.0;
double globalMin = 0.0;
double globalMax = 0.0;
double globalPosClosestToZero = 0.0;
double globalNegClosestToZero = 0.0;
auto valuesForTimeSteps = fractureSurface->valuesForProperty( m_propertyName );
MinMaxAccumulator minMaxAccumulator;
PosNegAccumulator posNegAccumulator;
for ( size_t timeIndex = 0; timeIndex < valuesForTimeSteps.size(); timeIndex++ )
{
auto values = valuesForTimeSteps[timeIndex];
minMaxAccumulator.addData( values );
posNegAccumulator.addData( values );
if ( static_cast<int>( timeIndex ) == currentTimeStep )
{
MinMaxAccumulator localMinMaxAccumulator;
PosNegAccumulator localPosNegAccumulator;
localMinMaxAccumulator.addData( values );
localPosNegAccumulator.addData( values );
localPosClosestToZero = localPosNegAccumulator.pos;
localNegClosestToZero = localPosNegAccumulator.neg;
localMin = localMinMaxAccumulator.min;
localMax = localMinMaxAccumulator.max;
}
}
globalPosClosestToZero = posNegAccumulator.pos;
globalNegClosestToZero = posNegAccumulator.neg;
globalMin = minMaxAccumulator.min;
globalMax = minMaxAccumulator.max;
m_legendConfig->setClosestToZeroValues( globalPosClosestToZero, globalNegClosestToZero, localPosClosestToZero, localNegClosestToZero );
m_legendConfig->setAutomaticRanges( globalMin, globalMax, localMin, localMax );
return;
}
RigSurface* surfData = surfaceData();
if ( surfData )
{
double globalMin = 0.0;
double globalMax = 0.0;
double globalPosClosestToZero = 0.0;
double globalNegClosestToZero = 0.0;
{
MinMaxAccumulator minMaxAccumulator;
PosNegAccumulator posNegAccumulator;
auto values = surfData->propertyValues( m_propertyName );
minMaxAccumulator.addData( values );
posNegAccumulator.addData( values );
globalPosClosestToZero = posNegAccumulator.pos;
globalNegClosestToZero = posNegAccumulator.neg;
globalMin = minMaxAccumulator.min;
globalMax = minMaxAccumulator.max;
}
m_legendConfig->setClosestToZeroValues( globalPosClosestToZero, globalNegClosestToZero, globalPosClosestToZero, globalNegClosestToZero );
m_legendConfig->setAutomaticRanges( globalMin, globalMax, globalMin, globalMax );
}
if ( auto surface = m_surfaceInView->surface() ) surface->updateMinMaxValues( m_legendConfig, m_propertyName, currentTimeStep );
}
//--------------------------------------------------------------------------------------------------
@@ -173,12 +99,12 @@ void RimSurfaceResultDefinition::updateMinMaxValues( int currentTimeStep )
//--------------------------------------------------------------------------------------------------
void RimSurfaceResultDefinition::assignDefaultProperty()
{
if ( m_surfaceInView->surface() && m_surfaceInView->surface()->surfaceData() )
if ( auto surface = surfaceData() )
{
auto propNames = m_surfaceInView->surface()->surfaceData()->propertyNames();
auto propNames = surface->propertyNames();
if ( !propNames.empty() )
{
m_propertyName = m_surfaceInView->surface()->surfaceData()->propertyNames().front();
m_propertyName = propNames.front();
}
}
}
@@ -24,8 +24,6 @@
#include "cafPdmObject.h"
#include "cafPdmPtrField.h"
#include "cvfObject.h"
class RimRegularLegendConfig;
class RimSurfaceInView;
class RigSurface;