mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add parsing of Pvd files
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "../../Fwk/VizFwk/LibIo/cvfTinyXmlFused.hpp"
|
||||
#include "RigGocadData.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -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<std::string>& proper
|
||||
dataArray = dataArray->NextSiblingElement( "DataArray" );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RifVtkSurfaceImporter::PVDDataset> parsePVDDatasets( const std::string& filename )
|
||||
{
|
||||
std::vector<PVDDataset> 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
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -37,13 +38,26 @@ class TiXmlElement;
|
||||
//==================================================================================================
|
||||
namespace RifVtkSurfaceImporter
|
||||
{
|
||||
|
||||
struct PvdDataset
|
||||
{
|
||||
double timestep;
|
||||
std::string filename;
|
||||
std::map<std::string, std::vector<float>> 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<cvf::Vec3d>& vertices );
|
||||
bool readConnectivity( const cvf_tinyXML::TiXmlElement* piece, std::vector<unsigned>& connectivity );
|
||||
void readProperties( const cvf_tinyXML::TiXmlElement* piece,
|
||||
std::vector<std::string>& propertyNames,
|
||||
std::vector<std::vector<float>>& propertyValues );
|
||||
|
||||
std::vector<PvdDataset> parsePvdDatasets( const std::string& filename );
|
||||
bool importDataset( const PvdDataset& dataset, RigGocadData* gocadData );
|
||||
|
||||
}; // namespace RifVtkSurfaceImporter
|
||||
|
||||
Reference in New Issue
Block a user