mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
VTK: read only scalar point data arrays as node properties
Vector arrays such as "disp" are read by readDisplacements and were parsed again only to be discarded by readNodalData.
This commit is contained in:
1 parent
5fa48d6e60
commit
cdf4e0fa64
3 files changed
+31
-4
No files matched your search
@@ -119,7 +119,7 @@ std::vector<unsigned> RifVtkImportUtil::readConnectivity( const pugi::xml_node&
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<std::string, std::vector<float>> RifVtkImportUtil::readProperties( const pugi::xml_node& piece )
|
||||
{
|
||||
return readDataArrays( piece.child( "CellData" ) );
|
||||
return readDataArrays( piece.child( "CellData" ), false );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -127,13 +127,14 @@ std::map<std::string, std::vector<float>> RifVtkImportUtil::readProperties( cons
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<std::string, std::vector<float>> RifVtkImportUtil::readPointProperties( const pugi::xml_node& piece )
|
||||
{
|
||||
return readDataArrays( piece.child( "PointData" ) );
|
||||
// Vector arrays such as "disp" are read by readDisplacements
|
||||
return readDataArrays( piece.child( "PointData" ), true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<std::string, std::vector<float>> RifVtkImportUtil::readDataArrays( const pugi::xml_node& data )
|
||||
std::map<std::string, std::vector<float>> RifVtkImportUtil::readDataArrays( const pugi::xml_node& data, bool scalarsOnly )
|
||||
{
|
||||
if ( !data ) return {};
|
||||
|
||||
@@ -141,6 +142,8 @@ std::map<std::string, std::vector<float>> RifVtkImportUtil::readDataArrays( cons
|
||||
|
||||
for ( const auto& dataArray : data.children( "DataArray" ) )
|
||||
{
|
||||
if ( scalarsOnly && dataArray.attribute( "NumberOfComponents" ).as_int( 1 ) != 1 ) continue;
|
||||
|
||||
const char* name = dataArray.attribute( "Name" ).value();
|
||||
if ( name && *name )
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
static std::map<std::string, std::vector<float>> readPointProperties( const pugi::xml_node& piece );
|
||||
|
||||
private:
|
||||
static std::map<std::string, std::vector<float>> readDataArrays( const pugi::xml_node& data );
|
||||
static std::map<std::string, std::vector<float>> readDataArrays( const pugi::xml_node& data, bool scalarsOnly );
|
||||
static std::vector<cvf::Vec3d> parseVec3ds( std::string_view text );
|
||||
static std::vector<cvf::Vec3f> parseVec3fs( std::string_view text );
|
||||
};
|
||||
@@ -280,3 +280,27 @@ TEST( RifVtkImportUtilTest, ReadProperties_MissingCellDataSection )
|
||||
auto properties = RifVtkImportUtil::readProperties( piece );
|
||||
EXPECT_TRUE( properties.empty() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// readPointProperties
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
TEST( RifVtkImportUtilTest, ReadPointProperties_SkipsVectorArrays )
|
||||
{
|
||||
pugi::xml_document doc;
|
||||
auto piece = parsePiece( doc, R"(
|
||||
<UnstructuredGrid>
|
||||
<Piece>
|
||||
<PointData>
|
||||
<DataArray type="Float32" Name="pressure" NumberOfComponents="1" format="ascii">1.0 2.0</DataArray>
|
||||
<DataArray type="Float32" Name="disp" NumberOfComponents="3" format="ascii">0 0 0 0 0 0</DataArray>
|
||||
</PointData>
|
||||
</Piece>
|
||||
</UnstructuredGrid>)" );
|
||||
|
||||
auto properties = RifVtkImportUtil::readPointProperties( piece );
|
||||
|
||||
ASSERT_EQ( properties.size(), 1u );
|
||||
ASSERT_TRUE( properties.count( "pressure" ) > 0 );
|
||||
EXPECT_FLOAT_EQ( properties["pressure"][1], 2.0f );
|
||||
}
|
||||
Reference in new issue
Block a user