From 29eb0589b6e7b6ca831eeca118a306b9ab4138e2 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 17 Jan 2025 14:45:42 +0100 Subject: [PATCH 01/11] Add surface import from VTU files Parse VTU files. If element results are detected, duplicate nodes and assign result values to nodes for display. --- .../RicImportSurfacesFeature.cpp | 2 +- .../FileInterface/CMakeLists_files.cmake | 2 + .../FileInterface/RifSurfaceImporter.cpp | 2 +- .../FileInterface/RifVtkSurfaceImporter.cpp | 196 ++++++++++++++++++ .../FileInterface/RifVtkSurfaceImporter.h | 49 +++++ .../Surfaces/RimFileSurface.cpp | 11 +- .../ReservoirDataModel/RigGocadData.cpp | 11 +- .../ReservoirDataModel/RigGocadData.h | 3 +- 8 files changed, 271 insertions(+), 5 deletions(-) create mode 100644 ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp create mode 100644 ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h diff --git a/ApplicationLibCode/Commands/SurfaceCommands/RicImportSurfacesFeature.cpp b/ApplicationLibCode/Commands/SurfaceCommands/RicImportSurfacesFeature.cpp index 01e932a15af..c1f8f17f672 100644 --- a/ApplicationLibCode/Commands/SurfaceCommands/RicImportSurfacesFeature.cpp +++ b/ApplicationLibCode/Commands/SurfaceCommands/RicImportSurfacesFeature.cpp @@ -45,7 +45,7 @@ void RicImportSurfacesFeature::onActionTriggered( bool isChecked ) QStringList fileNames = RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(), "Import Surfaces", defaultDir, - "Surface files (*.ptl *.ts *.dat *.xyz);;All Files (*.*)" ); + "Surface files (*.ptl *.ts *.dat *.vtu *.xyz);;All Files (*.*)" ); if ( fileNames.isEmpty() ) return; diff --git a/ApplicationLibCode/FileInterface/CMakeLists_files.cmake b/ApplicationLibCode/FileInterface/CMakeLists_files.cmake index 30ec40e901b..93fa7de074c 100644 --- a/ApplicationLibCode/FileInterface/CMakeLists_files.cmake +++ b/ApplicationLibCode/FileInterface/CMakeLists_files.cmake @@ -103,6 +103,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RifByteArrayArrowRandomAccessFile.h ${CMAKE_CURRENT_LIST_DIR}/RifArrowTools.h ${CMAKE_CURRENT_LIST_DIR}/RifReaderRegularGridModel.h + ${CMAKE_CURRENT_LIST_DIR}/RifVtkSurfaceImporter.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -203,6 +204,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RifByteArrayArrowRandomAccessFile.cpp ${CMAKE_CURRENT_LIST_DIR}/RifArrowTools.cpp ${CMAKE_CURRENT_LIST_DIR}/RifReaderRegularGridModel.cpp + ${CMAKE_CURRENT_LIST_DIR}/RifVtkSurfaceImporter.cpp ) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/FileInterface/RifSurfaceImporter.cpp b/ApplicationLibCode/FileInterface/RifSurfaceImporter.cpp index 70c012d001a..cb8689f0c61 100644 --- a/ApplicationLibCode/FileInterface/RifSurfaceImporter.cpp +++ b/ApplicationLibCode/FileInterface/RifSurfaceImporter.cpp @@ -207,7 +207,7 @@ void RifSurfaceImporter::readGocadFile( const QString& filename, RigGocadData* g if ( gocadData ) { gocadData->setGeometryData( vertices, triangleIndices ); - gocadData->addPropertyData( propertyNames, propertyValues ); + gocadData->setPropertyData( propertyNames, propertyValues ); } } diff --git a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp new file mode 100644 index 00000000000..c25257d9eab --- /dev/null +++ b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp @@ -0,0 +1,196 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RifVtkSurfaceImporter.h" + +#include "../../Fwk/VizFwk/LibIo/cvfTinyXmlFused.hpp" +#include "RigGocadData.h" + +#include +#include +#include +#include + +namespace RifVtkSurfaceImporter +{ +using namespace cvf_tinyXML; + +bool importFromFile( std::string filename, RigGocadData* gocadData ) +{ + TiXmlDocument doc; + if ( !doc.LoadFile( filename.c_str() ) ) + { + return false; + } + + return importFromXMLDoc( doc, gocadData ); +} + +bool importFromXMLDoc( const TiXmlDocument& doc, RigGocadData* gocadData ) +{ + auto* root = doc.FirstChildElement( "VTKFile" ); + if ( !root ) return false; + + auto* grid = root->FirstChildElement( "UnstructuredGrid" ); + if ( !grid ) return false; + + auto* piece = grid->FirstChildElement( "Piece" ); + if ( !piece ) return false; + + // Read points + std::vector vertices; + if ( !readPoints( piece, vertices ) ) + { + return false; + } + + // Read connectivity + std::vector connectivity; + if ( !readConnectivity( piece, connectivity ) ) + { + return false; + } + + // Avoid shared nodes + std::vector nonSharedVertices; + std::vector nonSharedConnectivity; + + const auto numTriangles = connectivity.size() / 3; + for ( size_t triangleIdx = 0; triangleIdx < numTriangles; triangleIdx++ ) + { + nonSharedVertices.push_back( vertices[connectivity[3 * triangleIdx + 0]] ); + nonSharedVertices.push_back( vertices[connectivity[3 * triangleIdx + 1]] ); + nonSharedVertices.push_back( vertices[connectivity[3 * triangleIdx + 2]] ); + + nonSharedConnectivity.push_back( static_cast( 3 * triangleIdx + 0 ) ); + nonSharedConnectivity.push_back( static_cast( 3 * triangleIdx + 1 ) ); + nonSharedConnectivity.push_back( static_cast( 3 * triangleIdx + 2 ) ); + } + + // Set geometry data + gocadData->setGeometryData( nonSharedVertices, nonSharedConnectivity ); + + // Read properties + std::vector propertyNamesOnFile; + std::vector> propertyValuesOnFile; + + readProperties( piece, propertyNamesOnFile, propertyValuesOnFile ); + + if ( propertyNamesOnFile.size() == propertyValuesOnFile.size() ) + { + for ( size_t i = 0; i < propertyValuesOnFile.size(); i++ ) + { + // These values are per element, so we need to duplicate them for each node + auto values = propertyValuesOnFile[i]; + if ( values.size() * 3 == nonSharedVertices.size() ) + { + std::vector valuesForEachNode; + for ( auto value : values ) + { + valuesForEachNode.push_back( value ); + valuesForEachNode.push_back( value ); + valuesForEachNode.push_back( value ); + } + + gocadData->addPropertyData( QString::fromStdString( propertyNamesOnFile[i] ), valuesForEachNode ); + } + } + } + + return true; +} + +bool readPoints( const TiXmlElement* piece, std::vector& vertices ) +{ + auto* points = piece->FirstChildElement( "Points" ); + if ( !points ) return false; + + auto* coords = points->FirstChildElement( "DataArray" ); + if ( !coords || strcmp( coords->Attribute( "Name" ), "Coordinates" ) != 0 ) return false; + + std::string coordsText = coords->GetText(); + std::istringstream iss( coordsText ); + + double x, y, z; + while ( iss >> x >> y >> z ) + { + vertices.push_back( cvf::Vec3d( x, y, -z ) ); + } + + return !vertices.empty(); +} + +bool readConnectivity( const TiXmlElement* piece, std::vector& connectivity ) +{ + auto* cells = piece->FirstChildElement( "Cells" ); + if ( !cells ) return false; + + auto* connectivityArray = cells->FirstChildElement( "DataArray" ); + while ( connectivityArray ) + { + if ( strcmp( connectivityArray->Attribute( "Name" ), "connectivity" ) == 0 ) + { + std::string connectivityText = connectivityArray->GetText(); + std::istringstream iss( connectivityText ); + + unsigned index; + while ( iss >> index ) + { + connectivity.push_back( index ); + } + break; + } + connectivityArray = connectivityArray->NextSiblingElement( "DataArray" ); + } + + return !connectivity.empty(); +} + +void readProperties( const TiXmlElement* piece, std::vector& propertyNames, std::vector>& propertyValues ) +{ + auto* cellData = piece->FirstChildElement( "CellData" ); + if ( !cellData ) return; + + auto* dataArray = cellData->FirstChildElement( "DataArray" ); + while ( dataArray ) + { + const char* name = dataArray->Attribute( "Name" ); + if ( name ) + { + std::vector values; + std::string valuesText = dataArray->GetText(); + std::istringstream iss( valuesText ); + + float value; + while ( iss >> value ) + { + values.push_back( value ); + } + + if ( !values.empty() ) + { + propertyNames.push_back( name ); + propertyValues.push_back( values ); + } + } + dataArray = dataArray->NextSiblingElement( "DataArray" ); + } +} +}; // namespace RifVtkSurfaceImporter diff --git a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h new file mode 100644 index 00000000000..2e6c9c91fe0 --- /dev/null +++ b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h @@ -0,0 +1,49 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include + +#include "cvfVector3.h" + +class RigGocadData; + +namespace cvf_tinyXML +{ +class TiXmlDocument; +class TiXmlElement; +} // namespace cvf_tinyXML + +//================================================================================================== +/// +//================================================================================================== +namespace RifVtkSurfaceImporter +{ +bool importFromFile( std::string filename, RigGocadData* gocadData ); + +bool importFromXMLDoc( const cvf_tinyXML::TiXmlDocument& doc, RigGocadData* gocadData ); +bool readPoints( const cvf_tinyXML::TiXmlElement* piece, std::vector& vertices ); +bool readConnectivity( const cvf_tinyXML::TiXmlElement* piece, std::vector& connectivity ); +void readProperties( const cvf_tinyXML::TiXmlElement* piece, + std::vector& propertyNames, + std::vector>& propertyValues ); + +}; // namespace RifVtkSurfaceImporter diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFileSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFileSurface.cpp index 6cdce72d8e5..dd20bd55dc2 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFileSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFileSurface.cpp @@ -20,11 +20,13 @@ #include "RiaPreferences.h" +#include "RimSurfaceCollection.h" + #include "RifSurfaceImporter.h" +#include "RifVtkSurfaceImporter.h" #include "RigGocadData.h" #include "RigSurface.h" -#include "RimSurfaceCollection.h" #include "cafPdmFieldScriptingCapability.h" #include "cafPdmObjectScriptingCapability.h" @@ -177,6 +179,13 @@ bool RimFileSurface::loadDataFromFile() surface = m_gocadData->gocadGeometry(); } + else if ( filePath.endsWith( "vtu", Qt::CaseInsensitive ) ) + { + m_gocadData = std::make_unique(); + RifVtkSurfaceImporter::importFromFile( filePath.toStdString(), m_gocadData.get() ); + + surface = m_gocadData->gocadGeometry(); + } else if ( filePath.endsWith( "dat", Qt::CaseInsensitive ) || filePath.endsWith( "xyz", Qt::CaseInsensitive ) ) { double resamplingDistance = RiaPreferences::current()->surfaceImportResamplingDistance(); diff --git a/ApplicationLibCode/ReservoirDataModel/RigGocadData.cpp b/ApplicationLibCode/ReservoirDataModel/RigGocadData.cpp index ea8e00c7e33..ba2fe06639d 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigGocadData.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigGocadData.cpp @@ -76,8 +76,17 @@ void RigGocadData::setGeometryData( const std::vector& nodeCoord, co //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RigGocadData::addPropertyData( const std::vector& propertyNames, std::vector>& propertyValues ) +void RigGocadData::setPropertyData( const std::vector& propertyNames, std::vector>& propertyValues ) { m_propertyNames = propertyNames; m_propertyValues = propertyValues; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigGocadData::addPropertyData( const QString& propertyName, std::vector& propertyValues ) +{ + m_propertyNames.push_back( propertyName ); + m_propertyValues.push_back( propertyValues ); +} diff --git a/ApplicationLibCode/ReservoirDataModel/RigGocadData.h b/ApplicationLibCode/ReservoirDataModel/RigGocadData.h index 0b862058c36..ff1aa593af8 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigGocadData.h +++ b/ApplicationLibCode/ReservoirDataModel/RigGocadData.h @@ -34,7 +34,8 @@ class RigGocadData std::vector propertyValues( const QString& property ); void setGeometryData( const std::vector& nodeCoord, const std::vector& connectivities ); - void addPropertyData( const std::vector& propertyNames, std::vector>& propertyValues ); + void setPropertyData( const std::vector& propertyNames, std::vector>& propertyValues ); + void addPropertyData( const QString& propertyName, std::vector& propertyValues ); private: std::vector m_vertices; From 019ebbdb4a160030f71b94896d4d6aa536eeab13 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 20 Jan 2025 18:30:13 +0100 Subject: [PATCH 02/11] Fix build --- ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp index c25257d9eab..4aae568d6e5 100644 --- a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp +++ b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp @@ -16,8 +16,6 @@ // ///////////////////////////////////////////////////////////////////////////////// -#pragma once - #include "RifVtkSurfaceImporter.h" #include "../../Fwk/VizFwk/LibIo/cvfTinyXmlFused.hpp" From 7a6395d1f4bc520860b41040e29b1c38811c68d9 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 20 Jan 2025 18:46:38 +0100 Subject: [PATCH 03/11] Fix clang --- ApplicationLibCode/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ApplicationLibCode/CMakeLists.txt b/ApplicationLibCode/CMakeLists.txt index 68be6908e19..6d41da77c3b 100644 --- a/ApplicationLibCode/CMakeLists.txt +++ b/ApplicationLibCode/CMakeLists.txt @@ -249,6 +249,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") -Wno-delete-non-abstract-non-virtual-dtor -Wno-ambiguous-reversed-operator -Wno-deprecated-declarations + -Wno-implicit-fallthrough ) endif() From 8aae7c22e20b6771c2bdabad06defb12958e8e6f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 20 Jan 2025 18:55:03 +0100 Subject: [PATCH 04/11] Fix gcc --- ApplicationLibCode/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ApplicationLibCode/CMakeLists.txt b/ApplicationLibCode/CMakeLists.txt index 6d41da77c3b..76cc6b9947c 100644 --- a/ApplicationLibCode/CMakeLists.txt +++ b/ApplicationLibCode/CMakeLists.txt @@ -232,7 +232,7 @@ endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options( - ApplicationLibCode PRIVATE -Wall -Wno-reorder -Wno-parentheses -Wno-switch + ApplicationLibCode PRIVATE -Wall -Wno-reorder -Wno-parentheses -Wno-switch -Wno-implicit-fallthrough ) endif() From acfa083cc702093990993eea1746df3cdb3a46be Mon Sep 17 00:00:00 2001 From: magnesj <1793152+magnesj@users.noreply.github.com> Date: Mon, 20 Jan 2025 17:55:37 +0000 Subject: [PATCH 05/11] Fixes by cmake-format --- ApplicationLibCode/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ApplicationLibCode/CMakeLists.txt b/ApplicationLibCode/CMakeLists.txt index 76cc6b9947c..f38bfcdf0df 100644 --- a/ApplicationLibCode/CMakeLists.txt +++ b/ApplicationLibCode/CMakeLists.txt @@ -232,7 +232,8 @@ endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options( - ApplicationLibCode PRIVATE -Wall -Wno-reorder -Wno-parentheses -Wno-switch -Wno-implicit-fallthrough + ApplicationLibCode PRIVATE -Wall -Wno-reorder -Wno-parentheses -Wno-switch + -Wno-implicit-fallthrough ) endif() From 79754d430e55e265a025b2c3f650a6e448264b5d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 23 Jan 2025 13:43:38 +0100 Subject: [PATCH 06/11] Add parsing of Pvd files --- .../FileInterface/RifVtkSurfaceImporter.cpp | 69 +++++++++++++++++++ .../FileInterface/RifVtkSurfaceImporter.h | 16 ++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp index 4aae568d6e5..6431828674d 100644 --- a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp +++ b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp @@ -21,6 +21,7 @@ #include "../../Fwk/VizFwk/LibIo/cvfTinyXmlFused.hpp" #include "RigGocadData.h" +#include #include #include #include @@ -41,6 +42,21 @@ bool importFromFile( std::string filename, RigGocadData* gocadData ) return importFromXMLDoc( doc, gocadData ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool importFromPVDFile( const std::string& filename, RigGocadData* gocadData ) +{ + auto datasets = parsePVDDatasets( filename ); + + if ( datasets.empty() ) return false; + + // Sort and import the most recent dataset + std::sort( datasets.begin(), datasets.end(), []( const PVDDataset& a, const PVDDataset& b ) { return a.timestep < b.timestep; } ); + + return importDataset( datasets.back(), gocadData ); +} + bool importFromXMLDoc( const TiXmlDocument& doc, RigGocadData* gocadData ) { auto* root = doc.FirstChildElement( "VTKFile" ); @@ -191,4 +207,57 @@ void readProperties( const TiXmlElement* piece, std::vector& proper dataArray = dataArray->NextSiblingElement( "DataArray" ); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector parsePVDDatasets( const std::string& filename ) +{ + std::vector datasets; + TiXmlDocument doc; + + if ( !doc.LoadFile( filename.c_str() ) ) return datasets; + + auto* root = doc.FirstChildElement( "VTKFile" ); + if ( !root ) return datasets; + + auto* collection = root->FirstChildElement( "Collection" ); + if ( !collection ) return datasets; + + std::string baseDir = std::filesystem::path( filename ).parent_path().string(); + + auto* datasetElem = collection->FirstChildElement( "DataSet" ); + while ( datasetElem ) + { + const char* file = datasetElem->Attribute( "file" ); + const char* timestepStr = datasetElem->Attribute( "timestep" ); + + if ( file && timestepStr ) + { + double timestep = std::stod( timestepStr ); + std::string fullPath = std::filesystem::absolute( std::filesystem::path( baseDir ) / file ).string(); + + datasets.push_back( { timestep, fullPath, {} } ); + } + + datasetElem = datasetElem->NextSiblingElement( "DataSet" ); + } + + return datasets; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool importDataset( const PVDDataset& dataset, RigGocadData* gocadData ) +{ + TiXmlDocument doc; + if ( !doc.LoadFile( dataset.filename.c_str() ) ) + { + return false; + } + + return importFromXMLDoc( doc, gocadData ); +} + }; // namespace RifVtkSurfaceImporter diff --git a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h index 2e6c9c91fe0..9ae82a66313 100644 --- a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h +++ b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h @@ -18,6 +18,7 @@ #pragma once +#include #include #include #include @@ -37,13 +38,26 @@ class TiXmlElement; //================================================================================================== namespace RifVtkSurfaceImporter { + +struct PvdDataset +{ + double timestep; + std::string filename; + std::map> properties; +}; + bool importFromFile( std::string filename, RigGocadData* gocadData ); -bool importFromXMLDoc( const cvf_tinyXML::TiXmlDocument& doc, RigGocadData* gocadData ); +bool importFromPvdFile( const std::string& filename, RigGocadData* gocadData ); +bool importFromXmlDoc( const cvf_tinyXML::TiXmlDocument& doc, RigGocadData* gocadData ); + bool readPoints( const cvf_tinyXML::TiXmlElement* piece, std::vector& vertices ); bool readConnectivity( const cvf_tinyXML::TiXmlElement* piece, std::vector& connectivity ); void readProperties( const cvf_tinyXML::TiXmlElement* piece, std::vector& propertyNames, std::vector>& propertyValues ); +std::vector parsePvdDatasets( const std::string& filename ); +bool importDataset( const PvdDataset& dataset, RigGocadData* gocadData ); + }; // namespace RifVtkSurfaceImporter From fbe83c4e4cbb889bc81c6e0163ea44fe926c7a57 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 23 Jan 2025 13:55:40 +0100 Subject: [PATCH 07/11] add fracturefile object --- .../FileInterface/RifVtkSurfaceImporter.cpp | 18 +- .../Surfaces/CMakeLists_files.cmake | 2 + .../Surfaces/RimFractureSurface.cpp | 207 ++++++++++++++++++ .../Surfaces/RimFractureSurface.h | 48 ++++ 4 files changed, 266 insertions(+), 9 deletions(-) create mode 100644 ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp create mode 100644 ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h diff --git a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp index 6431828674d..d44d5a986c6 100644 --- a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp +++ b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp @@ -39,25 +39,25 @@ bool importFromFile( std::string filename, RigGocadData* gocadData ) return false; } - return importFromXMLDoc( doc, gocadData ); + return importFromXmlDoc( doc, gocadData ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool importFromPVDFile( const std::string& filename, RigGocadData* gocadData ) +bool importFromPvdFile( const std::string& filename, RigGocadData* gocadData ) { - auto datasets = parsePVDDatasets( filename ); + auto datasets = parsePvdDatasets( filename ); if ( datasets.empty() ) return false; // Sort and import the most recent dataset - std::sort( datasets.begin(), datasets.end(), []( const PVDDataset& a, const PVDDataset& b ) { return a.timestep < b.timestep; } ); + std::sort( datasets.begin(), datasets.end(), []( const PvdDataset& a, const PvdDataset& b ) { return a.timestep < b.timestep; } ); return importDataset( datasets.back(), gocadData ); } -bool importFromXMLDoc( const TiXmlDocument& doc, RigGocadData* gocadData ) +bool importFromXmlDoc( const TiXmlDocument& doc, RigGocadData* gocadData ) { auto* root = doc.FirstChildElement( "VTKFile" ); if ( !root ) return false; @@ -211,9 +211,9 @@ void readProperties( const TiXmlElement* piece, std::vector& proper //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector parsePVDDatasets( const std::string& filename ) +std::vector parsePvdDatasets( const std::string& filename ) { - std::vector datasets; + std::vector datasets; TiXmlDocument doc; if ( !doc.LoadFile( filename.c_str() ) ) return datasets; @@ -249,7 +249,7 @@ std::vector parsePVDDatasets( const std::stri //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool importDataset( const PVDDataset& dataset, RigGocadData* gocadData ) +bool importDataset( const PvdDataset& dataset, RigGocadData* gocadData ) { TiXmlDocument doc; if ( !doc.LoadFile( dataset.filename.c_str() ) ) @@ -257,7 +257,7 @@ bool importDataset( const PVDDataset& dataset, RigGocadData* gocadData ) return false; } - return importFromXMLDoc( doc, gocadData ); + return importFromXmlDoc( doc, gocadData ); } }; // namespace RifVtkSurfaceImporter diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/CMakeLists_files.cmake b/ApplicationLibCode/ProjectDataModel/Surfaces/CMakeLists_files.cmake index b78f303ac14..c39fc349738 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/CMakeLists_files.cmake +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/CMakeLists_files.cmake @@ -9,6 +9,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleSurface.h ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsSurface.h ${CMAKE_CURRENT_LIST_DIR}/RimDepthSurface.h + ${CMAKE_CURRENT_LIST_DIR}/RimFractureSurface.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -22,6 +23,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleSurface.cpp ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsSurface.cpp ${CMAKE_CURRENT_LIST_DIR}/RimDepthSurface.cpp + ${CMAKE_CURRENT_LIST_DIR}/RimFractureSurface.cpp ) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp new file mode 100644 index 00000000000..735f41fd0df --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp @@ -0,0 +1,207 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RimFractureSurface.h" + +#include "RiaPreferences.h" + +#include "RimSurfaceCollection.h" + +#include "RifSurfaceImporter.h" +#include "RifVtkSurfaceImporter.h" + +#include "RigGocadData.h" +#include "RigSurface.h" + +#include "cafPdmFieldScriptingCapability.h" +#include "cafPdmObjectScriptingCapability.h" + +#include +#include + +CAF_PDM_SOURCE_INIT( RimFractureSurface, "RimFractureSurface" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFractureSurface::RimFractureSurface() +{ + CAF_PDM_InitScriptableObject( "Surface", ":/ReservoirSurface16x16.png" ); + + CAF_PDM_InitFieldNoDefault( &m_surfaceDefinitionFilePath, "SurfaceFilePath", "File" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFractureSurface::~RimFractureSurface() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFractureSurface::setSurfaceFilePath( const QString& filePath ) +{ + m_surfaceDefinitionFilePath = filePath; + + clearCachedNativeData(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimFractureSurface::surfaceFilePath() +{ + return m_surfaceDefinitionFilePath().path(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimFractureSurface::onLoadData() +{ + return updateSurfaceData(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimSurface* RimFractureSurface::createCopy() +{ + auto newSurface = copyObject(); + if ( !newSurface->onLoadData() ) + { + delete newSurface; + return nullptr; + } + + return newSurface; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFractureSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) +{ + RimSurface::fieldChangedByUi( changedField, oldValue, newValue ); + + if ( changedField == &m_surfaceDefinitionFilePath ) + { + clearCachedNativeData(); + updateSurfaceData(); + + auto surfColl = firstAncestorOrThisOfTypeAsserted(); + surfColl->updateViews( { this } ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// Regenerate the surface geometry, using the offset specified. +/// If the surface data hasn't been loaded from file yet, load it. +/// Returns false for fatal failure +//-------------------------------------------------------------------------------------------------- +bool RimFractureSurface::updateSurfaceData() +{ + bool result = true; + /* + if ( m_vertices.empty() ) + { + result = loadDataFromFile(); + } + + std::vector vertices{ m_vertices }; + std::vector tringleIndices{ m_tringleIndices }; + + auto surface = new RigSurface; + if ( !vertices.empty() && !tringleIndices.empty() ) + { + RimSurface::applyDepthOffsetIfNeeded( &vertices ); + + surface->setTriangleData( tringleIndices, vertices ); + } + + if ( m_gocadData ) + { + auto propertyNames = m_gocadData->propertyNames(); + for ( const auto& name : propertyNames ) + { + auto values = m_gocadData->propertyValues( name ); + surface->addVerticeResult( name, values ); + } + } + + setSurfaceData( surface ); + */ + + return result; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFractureSurface::clearCachedNativeData() +{ + /* + m_vertices.clear(); + m_tringleIndices.clear(); + */ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimFractureSurface::loadDataFromFile() +{ + return false; + + /* + std::pair, std::vector> surface; + + QString filePath = surfaceFilePath(); + if ( filePath.endsWith( "ptl", Qt::CaseInsensitive ) ) + { + surface = RifSurfaceImporter::readPetrelFile( filePath ); + } + else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) ) + { + m_gocadData = std::make_unique(); + + RifSurfaceImporter::readGocadFile( filePath, m_gocadData.get() ); + + surface = m_gocadData->gocadGeometry(); + } + else if ( filePath.endsWith( "vtu", Qt::CaseInsensitive ) ) + { + m_gocadData = std::make_unique(); + RifVtkSurfaceImporter::importFromFile( filePath.toStdString(), m_gocadData.get() ); + + surface = m_gocadData->gocadGeometry(); + } + else if ( filePath.endsWith( "dat", Qt::CaseInsensitive ) || filePath.endsWith( "xyz", Qt::CaseInsensitive ) ) + { + double resamplingDistance = RiaPreferences::current()->surfaceImportResamplingDistance(); + surface = RifSurfaceImporter::readOpenWorksXyzFile( filePath, resamplingDistance ); + } + + m_vertices = surface.first; + m_tringleIndices = surface.second; + + return !( m_vertices.empty() || m_tringleIndices.empty() ); +*/ +} diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h new file mode 100644 index 00000000000..c79ef7a7920 --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h @@ -0,0 +1,48 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RimSurface.h" + +class RimFractureSurface : public RimSurface +{ + CAF_PDM_HEADER_INIT; + +public: + RimFractureSurface(); + ~RimFractureSurface() override; + + void setSurfaceFilePath( const QString& filePath ); + QString surfaceFilePath(); + + bool onLoadData() override; + RimSurface* createCopy() override; + +protected: + bool updateSurfaceData() override; + void clearCachedNativeData() override; + +private: + bool loadDataFromFile(); + +private: + void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; + + caf::PdmField m_surfaceDefinitionFilePath; +}; From 61671adc1c81af7a42b747187b8861261d728dd0 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 28 Jan 2025 18:05:32 +0100 Subject: [PATCH 08/11] wip import pvd --- .../RicImportSurfacesFeature.cpp | 2 +- .../FileInterface/RifVtkSurfaceImporter.cpp | 2 +- .../FileInterface/RifVtkSurfaceImporter.h | 5 ++--- .../Surfaces/RimFractureSurface.cpp | 21 +++++++++++++++++++ .../Surfaces/RimFractureSurface.h | 8 +++++++ .../Surfaces/RimSurfaceCollection.cpp | 21 +++++++++++++++---- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/ApplicationLibCode/Commands/SurfaceCommands/RicImportSurfacesFeature.cpp b/ApplicationLibCode/Commands/SurfaceCommands/RicImportSurfacesFeature.cpp index c1f8f17f672..21be79899a2 100644 --- a/ApplicationLibCode/Commands/SurfaceCommands/RicImportSurfacesFeature.cpp +++ b/ApplicationLibCode/Commands/SurfaceCommands/RicImportSurfacesFeature.cpp @@ -45,7 +45,7 @@ void RicImportSurfacesFeature::onActionTriggered( bool isChecked ) QStringList fileNames = RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(), "Import Surfaces", defaultDir, - "Surface files (*.ptl *.ts *.dat *.vtu *.xyz);;All Files (*.*)" ); + "Surface files (*.ptl *.ts *.dat *.vtu *.pvd *.xyz);;All Files (*.*)" ); if ( fileNames.isEmpty() ) return; diff --git a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp index d44d5a986c6..898e1261a0f 100644 --- a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp +++ b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp @@ -237,7 +237,7 @@ std::vector parsePvdDatasets( const std::stri double timestep = std::stod( timestepStr ); std::string fullPath = std::filesystem::absolute( std::filesystem::path( baseDir ) / file ).string(); - datasets.push_back( { timestep, fullPath, {} } ); + datasets.push_back( { timestep, fullPath } ); } datasetElem = datasetElem->NextSiblingElement( "DataSet" ); diff --git a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h index 9ae82a66313..1987a0013f0 100644 --- a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h +++ b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.h @@ -41,9 +41,8 @@ namespace RifVtkSurfaceImporter struct PvdDataset { - double timestep; - std::string filename; - std::map> properties; + double timestep; + std::string filename; }; bool importFromFile( std::string filename, RigGocadData* gocadData ); diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp index 735f41fd0df..27e2dda12c1 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp @@ -119,6 +119,12 @@ void RimFractureSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedFie bool RimFractureSurface::updateSurfaceData() { bool result = true; + + if ( m_surfacePerTimeStep.empty() ) + { + loadDataFromFile(); + } + /* if ( m_vertices.empty() ) { @@ -157,6 +163,9 @@ bool RimFractureSurface::updateSurfaceData() //-------------------------------------------------------------------------------------------------- void RimFractureSurface::clearCachedNativeData() { + m_secondsSinceSimulationStart.clear(); + m_surfacePerTimeStep.clear(); + /* m_vertices.clear(); m_tringleIndices.clear(); @@ -168,6 +177,18 @@ void RimFractureSurface::clearCachedNativeData() //-------------------------------------------------------------------------------------------------- bool RimFractureSurface::loadDataFromFile() { + auto surfaceInfo = RifVtkSurfaceImporter::parsePvdDatasets( m_surfaceDefinitionFilePath().path().toStdString() ); + + for ( const auto& s : surfaceInfo ) + { + RigGocadData gocadData; + if ( RifVtkSurfaceImporter::importFromFile( s.filename, &gocadData ) ) + { + m_secondsSinceSimulationStart.push_back( s.timestep ); + m_surfacePerTimeStep.push_back( gocadData ); + } + } + return false; /* diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h index c79ef7a7920..728039853f9 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h @@ -20,6 +20,11 @@ #include "RimSurface.h" +#include "cafPdmChildArrayField.h" + +class RimFileSurface; +class RigGocadData; + class RimFractureSurface : public RimSurface { CAF_PDM_HEADER_INIT; @@ -45,4 +50,7 @@ class RimFractureSurface : public RimSurface void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; caf::PdmField m_surfaceDefinitionFilePath; + + std::vector m_secondsSinceSimulationStart; + std::vector m_surfacePerTimeStep; }; diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceCollection.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceCollection.cpp index 0e668da9b12..b81f689d98c 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceCollection.cpp @@ -41,6 +41,7 @@ #include "cafPdmFieldScriptingCapability.h" #include "cafPdmObjectScriptingCapability.h" +#include "RimFractureSurface.h" #include #include @@ -142,14 +143,26 @@ RimSurface* RimSurfaceCollection::importSurfacesFromFiles( const QStringList& fi for ( const QString& newFileName : fileNames ) { - RimFileSurface* newSurface = new RimFileSurface; + RimSurface* newSurface = nullptr; - auto newColor = RiaColorTables::categoryPaletteColors().cycledColor3f( existingSurfCount + newSurfCount ); + if ( newFileName.endsWith( ".pvd" ) ) + { + RimFractureSurface* fractureSurface = new RimFractureSurface; + fractureSurface->setSurfaceFilePath( newFileName ); - newSurface->setSurfaceFilePath( newFileName ); - newSurface->setUserDescription( QFileInfo( newFileName ).fileName() ); + newSurface = fractureSurface; + } + else + { + RimFileSurface* fileSurface = new RimFileSurface; + + fileSurface->setSurfaceFilePath( newFileName ); + newSurface = fileSurface; + } + auto newColor = RiaColorTables::categoryPaletteColors().cycledColor3f( existingSurfCount + newSurfCount ); newSurface->setColor( newColor ); + newSurface->setUserDescription( QFileInfo( newFileName ).fileName() ); if ( !newSurface->onLoadData() ) { From 741dc63af5143917a896b570b8465c272c3b3334 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 31 Jan 2025 15:57:32 +0100 Subject: [PATCH 09/11] working concept with time steps --- .../GeoMech/RimGeoMechView.cpp | 2 +- .../ProjectDataModel/RimEclipseView.cpp | 4 +- .../Seismic/RimSeismicView.cpp | 2 +- .../Surfaces/RimFractureSurface.cpp | 101 +++++------------- .../Surfaces/RimFractureSurface.h | 2 + .../ProjectDataModel/Surfaces/RimSurface.cpp | 7 ++ .../ProjectDataModel/Surfaces/RimSurface.h | 1 + .../Surfaces/RimSurfaceInView.cpp | 4 +- .../Surfaces/RimSurfaceInView.h | 2 +- .../Surfaces/RimSurfaceInViewCollection.cpp | 6 +- .../Surfaces/RimSurfaceInViewCollection.h | 2 +- 11 files changed, 52 insertions(+), 81 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechView.cpp b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechView.cpp index f48e5e05d5d..d4c25d6399c 100644 --- a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechView.cpp +++ b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechView.cpp @@ -195,7 +195,7 @@ void RimGeoMechView::onLoadDataAndUpdate() geoMechPropertyFilterCollection()->loadAndInitializePropertyFilters(); m_wellMeasurementCollection->syncWithChangesInWellMeasurementCollection(); - if ( m_surfaceCollection ) m_surfaceCollection->loadData(); + if ( m_surfaceCollection ) m_surfaceCollection->loadData( m_currentTimeStep ); if ( m_partsCollection ) m_partsCollection->syncWithCase( m_geomechCase ); diff --git a/ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp index 5f3e4a17595..3db04eb4c12 100644 --- a/ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp @@ -877,6 +877,8 @@ void RimEclipseView::onUpdateDisplayModelForCurrentTimeStep() appendIntersectionsForCurrentTimeStep(); } + if ( surfaceInViewCollection() ) surfaceInViewCollection()->loadData( m_currentTimeStep ); + updateVisibleCellColors(); wellCollection()->scaleWellDisks(); @@ -1197,7 +1199,7 @@ void RimEclipseView::onLoadDataAndUpdate() m_wellCollection->scaleWellDisks(); - if ( m_surfaceCollection ) m_surfaceCollection->loadData(); + if ( m_surfaceCollection ) m_surfaceCollection->loadData( m_currentTimeStep ); scheduleReservoirGridGeometryRegen(); m_simWellsPartManager->clearGeometryCache(); diff --git a/ApplicationLibCode/ProjectDataModel/Seismic/RimSeismicView.cpp b/ApplicationLibCode/ProjectDataModel/Seismic/RimSeismicView.cpp index c5bed5b6bec..765237bb288 100644 --- a/ApplicationLibCode/ProjectDataModel/Seismic/RimSeismicView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Seismic/RimSeismicView.cpp @@ -413,7 +413,7 @@ void RimSeismicView::onLoadDataAndUpdate() updateMdiWindowVisibility(); - if ( m_surfaceCollection ) m_surfaceCollection->loadData(); + if ( m_surfaceCollection ) m_surfaceCollection->loadData( m_currentTimeStep ); scheduleCreateDisplayModelAndRedraw(); } diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp index 27e2dda12c1..0da7971284e 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp @@ -94,6 +94,33 @@ RimSurface* RimFractureSurface::createCopy() return newSurface; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFractureSurface::loadSurfaceDataForTimeStep( int timeStep ) +{ + if ( m_surfacePerTimeStep.empty() ) + { + loadDataFromFile(); + } + + if ( timeStep >= m_surfacePerTimeStep.size() ) return; + + auto surface = new RigSurface; + + auto gocadData = m_surfacePerTimeStep[timeStep]; + const auto& [coordinates, indices] = gocadData.gocadGeometry(); + + surface->setTriangleData( indices, coordinates ); + auto propertyNames = gocadData.propertyNames(); + for ( const auto& name : propertyNames ) + { + auto values = gocadData.propertyValues( name ); + surface->addVerticeResult( name, values ); + } + setSurfaceData( surface ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -118,44 +145,9 @@ void RimFractureSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedFie //-------------------------------------------------------------------------------------------------- bool RimFractureSurface::updateSurfaceData() { - bool result = true; - - if ( m_surfacePerTimeStep.empty() ) - { - loadDataFromFile(); - } - - /* - if ( m_vertices.empty() ) - { - result = loadDataFromFile(); - } - - std::vector vertices{ m_vertices }; - std::vector tringleIndices{ m_tringleIndices }; + loadSurfaceDataForTimeStep( 0 ); - auto surface = new RigSurface; - if ( !vertices.empty() && !tringleIndices.empty() ) - { - RimSurface::applyDepthOffsetIfNeeded( &vertices ); - - surface->setTriangleData( tringleIndices, vertices ); - } - - if ( m_gocadData ) - { - auto propertyNames = m_gocadData->propertyNames(); - for ( const auto& name : propertyNames ) - { - auto values = m_gocadData->propertyValues( name ); - surface->addVerticeResult( name, values ); - } - } - - setSurfaceData( surface ); - */ - - return result; + return true; } //-------------------------------------------------------------------------------------------------- @@ -190,39 +182,4 @@ bool RimFractureSurface::loadDataFromFile() } return false; - - /* - std::pair, std::vector> surface; - - QString filePath = surfaceFilePath(); - if ( filePath.endsWith( "ptl", Qt::CaseInsensitive ) ) - { - surface = RifSurfaceImporter::readPetrelFile( filePath ); - } - else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) ) - { - m_gocadData = std::make_unique(); - - RifSurfaceImporter::readGocadFile( filePath, m_gocadData.get() ); - - surface = m_gocadData->gocadGeometry(); - } - else if ( filePath.endsWith( "vtu", Qt::CaseInsensitive ) ) - { - m_gocadData = std::make_unique(); - RifVtkSurfaceImporter::importFromFile( filePath.toStdString(), m_gocadData.get() ); - - surface = m_gocadData->gocadGeometry(); - } - else if ( filePath.endsWith( "dat", Qt::CaseInsensitive ) || filePath.endsWith( "xyz", Qt::CaseInsensitive ) ) - { - double resamplingDistance = RiaPreferences::current()->surfaceImportResamplingDistance(); - surface = RifSurfaceImporter::readOpenWorksXyzFile( filePath, resamplingDistance ); - } - - m_vertices = surface.first; - m_tringleIndices = surface.second; - - return !( m_vertices.empty() || m_tringleIndices.empty() ); -*/ } diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h index 728039853f9..1d0f40278c3 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h @@ -39,6 +39,8 @@ class RimFractureSurface : public RimSurface bool onLoadData() override; RimSurface* createCopy() override; + void loadSurfaceDataForTimeStep( int timeStep ) override; + protected: bool updateSurfaceData() override; void clearCachedNativeData() override; diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp index d6bc2bcabd5..b5244177f5b 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.cpp @@ -221,6 +221,13 @@ RigSurface* RimSurface::surfaceData() return m_surfaceData.p(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSurface::loadSurfaceDataForTimeStep( int timeStep ) +{ +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h index 1177f402cf4..0385fc43adf 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurface.h @@ -60,6 +60,7 @@ class RimSurface : public caf::PdmObject QString userDescription(); void setUserDescription( const QString& description ); + virtual void loadSurfaceDataForTimeStep( int timeStep ); virtual QString fullName() const; virtual bool onLoadData() = 0; virtual RimSurface* createCopy() = 0; diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.cpp index 9451addc1cc..78885cada11 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.cpp @@ -32,6 +32,7 @@ #include "RivSurfacePartMgr.h" +#include "RiaApplication.h" #include "cafPdmUiDoubleSliderEditor.h" CAF_PDM_SOURCE_INIT( RimSurfaceInView, "SurfaceInView" ); @@ -166,11 +167,12 @@ const RivIntersectionGeometryGeneratorInterface* RimSurfaceInView::intersectionG //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimSurfaceInView::loadDataAndUpdate() +void RimSurfaceInView::loadDataAndUpdate( int timeStep ) { if ( surface() ) { surface()->loadDataIfRequired(); + surface()->loadSurfaceDataForTimeStep( timeStep ); if ( surface()->surfaceData() && surface()->surfaceData()->propertyNames().empty() ) { diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.h index a94dbd5ca70..93c4a6542db 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInView.h @@ -56,7 +56,7 @@ class RimSurfaceInView : public RimIntersection RivSurfacePartMgr* nativeSurfacePartMgr(); const RivIntersectionGeometryGeneratorInterface* intersectionGeometryGenerator() const override; - void loadDataAndUpdate(); + void loadDataAndUpdate( int timeStep ); void updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer, bool isUsingOverrideViewer ); diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp index 85dd50db063..8fe41dbd40d 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp @@ -243,18 +243,18 @@ void RimSurfaceInViewCollection::updateFromSurfaceCollection() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimSurfaceInViewCollection::loadData() +void RimSurfaceInViewCollection::loadData( int timeStep ) { for ( RimSurfaceInViewCollection* coll : m_collectionsInView ) { - coll->loadData(); + coll->loadData( timeStep ); } for ( RimSurfaceInView* surf : m_surfacesInView ) { if ( surf->isActive() ) { - surf->loadDataAndUpdate(); + surf->loadDataAndUpdate( timeStep ); } } } diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h index 494b772867c..34b502dbc2d 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h @@ -54,7 +54,7 @@ class RimSurfaceInViewCollection : public RimCheckableNamedObject void setSurfaceCollection( RimSurfaceCollection* surfcoll ); void updateFromSurfaceCollection(); - void loadData(); + void loadData( int timeStep ); void clearGeometry(); void appendPartsToModel( cvf::ModelBasicList* surfaceVizModel, cvf::Transform* scaleTransform, bool onlyNativeParts = false ); From ac984d4e7ba28446279795ef471b95322294349f Mon Sep 17 00:00:00 2001 From: Magne Date: Thu, 6 Feb 2025 11:06:20 +0100 Subject: [PATCH 10/11] build fix --- .../ProjectDataModel/Surfaces/RimFractureSurface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp index 0da7971284e..f4031d2b433 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp @@ -104,7 +104,7 @@ void RimFractureSurface::loadSurfaceDataForTimeStep( int timeStep ) loadDataFromFile(); } - if ( timeStep >= m_surfacePerTimeStep.size() ) return; + if ( timeStep >= static_cast(m_surfacePerTimeStep.size()) ) return; auto surface = new RigSurface; From 1ffe1095d2e5971d8c04859385b3c49f17a74d96 Mon Sep 17 00:00:00 2001 From: magnesj <1793152+magnesj@users.noreply.github.com> Date: Thu, 6 Feb 2025 10:07:05 +0000 Subject: [PATCH 11/11] Fixes by clang-format --- .../ProjectDataModel/Surfaces/RimFractureSurface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp index f4031d2b433..81f5ed87b06 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp @@ -104,7 +104,7 @@ void RimFractureSurface::loadSurfaceDataForTimeStep( int timeStep ) loadDataFromFile(); } - if ( timeStep >= static_cast(m_surfacePerTimeStep.size()) ) return; + if ( timeStep >= static_cast( m_surfacePerTimeStep.size() ) ) return; auto surface = new RigSurface;