From 454a24f57ac54a763605bccb6cadc75453851d48 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 25 Oct 2024 17:18:21 +0200 Subject: [PATCH 01/22] rootGroup might contain dataset, load it if it is there --- mdal/frmts/mdal_xmdf.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index c09d5fa0..8e245cda 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -206,6 +206,17 @@ void MDAL::DriverXmdf::addDatasetGroupsFromXmdfGroup( DatasetGroups &groups, size_t vertexCount, size_t faceCount ) const { + // check if this root group can be loaded as a dataset group and if so, then load it + std::vector gDataNames = rootGroup.datasets(); + if ( MDAL::contains( gDataNames, "Times" ) && + MDAL::contains( gDataNames, "Values" ) && + MDAL::contains( gDataNames, "Mins" ) && + MDAL::contains( gDataNames, "Maxs" ) ) + { + std::shared_ptr ds = readXmdfGroupAsDatasetGroup( rootGroup, rootGroup.name() + nameSuffix, vertexCount, faceCount ); + groups.push_back( ds ); + } + for ( const std::string &groupName : rootGroup.groups() ) { HdfGroup g = rootGroup.group( groupName ); From b17ccbd38dc36c210b64d8bfdfb81720f5bcbdf0 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 25 Oct 2024 17:19:07 +0200 Subject: [PATCH 02/22] read mesh from xmdf --- mdal/frmts/mdal_xmdf.cpp | 168 ++++++++++++++++++++++++++++++++++++++- mdal/frmts/mdal_xmdf.hpp | 3 + 2 files changed, 170 insertions(+), 1 deletion(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 8e245cda..13febe9a 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -93,7 +93,7 @@ MDAL::DriverXmdf::DriverXmdf() : Driver( "XMDF", "TUFLOW XMDF", "*.xmdf", - Capability::ReadDatasets ) + Capability::ReadDatasets | Capability::ReadMesh ) { } @@ -342,3 +342,169 @@ std::shared_ptr MDAL::DriverXmdf::readXmdfGroupAsDatasetGrou return group; } + +bool MDAL::DriverXmdf::canReadMesh( const std::string &uri ) +{ + HdfFile file( uri, HdfFile::ReadOnly ); + if ( !file.isValid() ) + { + return false; + } + + HdfDataset dsFileType = file.dataset( "/File Type" ); + if ( dsFileType.readString() != "Xmdf" ) + { + return false; + } + + std::vector rootGroups = file.groups(); + if ( rootGroups.empty() || !MDAL::contains( rootGroups, "2DMeshModule" ) ) + { + return false; + } + + HdfGroup meshModuleGroup = file.group( "2DMeshModule" ); + + std::vector gGroupNames = meshModuleGroup.groups(); + + HdfGroup firstGroupMeshModule = meshModuleGroup.group( gGroupNames[0] ); + + if ( !firstGroupMeshModule.isValid() ) + { + return false; + } + + std::vector gDataNames = firstGroupMeshModule.groups(); + + if ( !MDAL::contains( gDataNames, "Nodes" ) || + !MDAL::contains( gDataNames, "Elements" ) ) + { + return false; + } + + return true; +} + +std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFile, const std::string &meshName ) +{ + mDatFile = meshFile; + + MDAL::Log::resetLastStatus(); + + HdfFile file( mDatFile, HdfFile::ReadOnly ); + if ( !file.isValid() ) + { + MDAL::Log::error( MDAL_Status::Err_UnknownFormat, name(), "File " + mDatFile + " is not valid" ); + return nullptr; + } + + HdfDataset dsFileType = file.dataset( "/File Type" ); + if ( dsFileType.readString() != "Xmdf" ) + { + MDAL::Log::error( MDAL_Status::Err_UnknownFormat, name(), "Unknown dataset file type" ); + return nullptr; + } + + std::vector rootGroups = file.groups(); + if ( rootGroups.empty() ) + { + MDAL::Log::error( MDAL_Status::Err_UnknownFormat, name(), "Expecting at least one root group for the mesh data" ); + return nullptr; + } + + HdfGroup meshModuleGroup = file.group( "2DMeshModule" ); + + std::vector gGroupNames = meshModuleGroup.groups(); + + HdfGroup firstGroupMeshModule = meshModuleGroup.group( gGroupNames[0] ); + + std::vector gDataNames = firstGroupMeshModule.groups(); + + HdfGroup gNodes = firstGroupMeshModule.group( "Nodes" ); + + std::vector namesNodes = gNodes.datasets(); + HdfDataset nodes = gNodes.dataset( namesNodes[0] ); + + std::vector nodesDims = nodes.dims(); + hsize_t nodesRows = nodesDims[0]; + size_t vertexDims = nodesDims[1]; + + std::vector nodesData = nodes.readArrayDouble(); + + Vertices vertices( nodesRows ); + + size_t i = 0; + while ( i < nodesRows ) + { + Vertex &vertex = vertices[i]; + + vertex.x = nodesData[i]; + i++; + vertex.y = nodesData[i]; + i++; + if ( vertexDims == 3 ) + { + vertex.z = nodesData[i]; + i++; + } + } + + nodesData.clear(); + + HdfGroup gElements = firstGroupMeshModule.group( "Elements" ); + + std::vector namesElements = gElements.datasets(); + HdfDataset elements = gElements.dataset( namesElements[0] ); + + std::vector elementsDims = elements.dims(); + hsize_t elementsRows = elementsDims[0]; + int elementsRowsDims = elementsDims[1]; + + std::vector facesData = elements.readArrayInt(); + + Faces faces( elementsRows ); + int maxVerticesPerFace = 0; + + i = 0; + + size_t currentFaceIndex = 0; + while ( i < elementsRows ) + { + Face &face = faces[currentFaceIndex]; + + for ( int j = 0; j < elementsRowsDims; j++ ) + { + int vertexIndex = facesData[i]; + if ( vertexIndex > 0 ) + { + // XMDF is 1-based, MDAL is 0-based + face.push_back( facesData[i] - 1 ); + } + + if ( j > maxVerticesPerFace ) + { + maxVerticesPerFace = j; + } + + i++; + } + + currentFaceIndex++; + } + + facesData.clear(); + + // create the mesh and set the required data + std::unique_ptr< MemoryMesh > mesh( + new MemoryMesh( + name(), + maxVerticesPerFace, + mDatFile + ) + ); + + mesh->setFaces( std::move( faces ) ); + mesh->setVertices( std::move( vertices ) ); + + return mesh; +} \ No newline at end of file diff --git a/mdal/frmts/mdal_xmdf.hpp b/mdal/frmts/mdal_xmdf.hpp index cd565034..1ca88815 100644 --- a/mdal/frmts/mdal_xmdf.hpp +++ b/mdal/frmts/mdal_xmdf.hpp @@ -89,6 +89,9 @@ namespace MDAL bool canReadDatasets( const std::string &uri ) override; void load( const std::string &datFile, Mesh *mesh ) override; + bool canReadMesh( const std::string &uri ) override; + std::unique_ptr< Mesh > load( const std::string &meshFile, const std::string &meshName = "" ) override; + private: MDAL::Mesh *mMesh = nullptr; std::string mDatFile; From e9a90a0a8e991f72f92640c8dad629d0aca3c245 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Mon, 28 Oct 2024 07:58:30 +0100 Subject: [PATCH 03/22] fix reading --- mdal/frmts/mdal_xmdf.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 13febe9a..ac17dfb3 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -433,10 +433,11 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil Vertices vertices( nodesRows ); + size_t currentVertexIndex = 0; size_t i = 0; - while ( i < nodesRows ) + while ( i < nodesData.size() ) { - Vertex &vertex = vertices[i]; + Vertex &vertex = vertices[currentVertexIndex]; vertex.x = nodesData[i]; i++; @@ -447,6 +448,7 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil vertex.z = nodesData[i]; i++; } + currentVertexIndex++; } nodesData.clear(); @@ -465,13 +467,11 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil Faces faces( elementsRows ); int maxVerticesPerFace = 0; - i = 0; - size_t currentFaceIndex = 0; - while ( i < elementsRows ) + i = 0; + while ( i < facesData.size() ) { Face &face = faces[currentFaceIndex]; - for ( int j = 0; j < elementsRowsDims; j++ ) { int vertexIndex = facesData[i]; @@ -481,14 +481,13 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil face.push_back( facesData[i] - 1 ); } - if ( j > maxVerticesPerFace ) + if ( j + 1 > maxVerticesPerFace ) { - maxVerticesPerFace = j; + maxVerticesPerFace = j + 1; } i++; } - currentFaceIndex++; } From d44b117c8dec45cc61a3a22aed6419fe1524ce9e Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Tue, 29 Oct 2024 17:08:28 +0100 Subject: [PATCH 04/22] add debug log --- mdal/frmts/mdal_xmdf.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index ac17dfb3..af13513e 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -360,6 +360,7 @@ bool MDAL::DriverXmdf::canReadMesh( const std::string &uri ) std::vector rootGroups = file.groups(); if ( rootGroups.empty() || !MDAL::contains( rootGroups, "2DMeshModule" ) ) { + MDAL::Log::debug( "Mesh from `" + mDatFile + "` does not contain group `2DMeshModule`."); return false; } @@ -371,6 +372,7 @@ bool MDAL::DriverXmdf::canReadMesh( const std::string &uri ) if ( !firstGroupMeshModule.isValid() ) { + MDAL::Log::debug( "Mesh Group module `" + firstGroupMeshModule.name() + "` is not valid."); return false; } @@ -379,6 +381,7 @@ bool MDAL::DriverXmdf::canReadMesh( const std::string &uri ) if ( !MDAL::contains( gDataNames, "Nodes" ) || !MDAL::contains( gDataNames, "Elements" ) ) { + MDAL::Log::debug( "Mesh Group module `" + firstGroupMeshModule.name() + "` does not contain `Nodes` and `Elements` groups."); return false; } From e0a30edf40540bc183e0c93dcc21f0deb9657b81 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Thu, 31 Oct 2024 13:08:51 +0100 Subject: [PATCH 05/22] add debug messages to see why not loaded --- mdal/frmts/mdal_xmdf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index af13513e..61705eac 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -360,7 +360,7 @@ bool MDAL::DriverXmdf::canReadMesh( const std::string &uri ) std::vector rootGroups = file.groups(); if ( rootGroups.empty() || !MDAL::contains( rootGroups, "2DMeshModule" ) ) { - MDAL::Log::debug( "Mesh from `" + mDatFile + "` does not contain group `2DMeshModule`."); + MDAL::Log::debug( "Mesh from `" + mDatFile + "` does not contain group `2DMeshModule`." ); return false; } @@ -372,7 +372,7 @@ bool MDAL::DriverXmdf::canReadMesh( const std::string &uri ) if ( !firstGroupMeshModule.isValid() ) { - MDAL::Log::debug( "Mesh Group module `" + firstGroupMeshModule.name() + "` is not valid."); + MDAL::Log::debug( "Mesh Group module `" + firstGroupMeshModule.name() + "` is not valid." ); return false; } @@ -381,7 +381,7 @@ bool MDAL::DriverXmdf::canReadMesh( const std::string &uri ) if ( !MDAL::contains( gDataNames, "Nodes" ) || !MDAL::contains( gDataNames, "Elements" ) ) { - MDAL::Log::debug( "Mesh Group module `" + firstGroupMeshModule.name() + "` does not contain `Nodes` and `Elements` groups."); + MDAL::Log::debug( "Mesh Group module `" + firstGroupMeshModule.name() + "` does not contain `Nodes` and `Elements` groups." ); return false; } From 9e3b0b8f84386cce784fd9c04afddd1f28a5aa17 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Thu, 31 Oct 2024 13:09:09 +0100 Subject: [PATCH 06/22] add scalar dataset group --- mdal/frmts/mdal_xmdf.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 61705eac..d87617d5 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -505,8 +505,16 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil ) ); + std::vector values( vertices.size() ); + for ( size_t i = 0; i < vertices.size(); ++i ) + { + values[i] = vertices[i].z; + } + mesh->setFaces( std::move( faces ) ); mesh->setVertices( std::move( vertices ) ); + addVertexScalarDatasetGroup( mesh.get(), values, "Z-Values" ); + return mesh; } \ No newline at end of file From 628932040286ddfa63dd35b09fc3c8f5cdbe9a1a Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Thu, 31 Oct 2024 20:34:34 +0100 Subject: [PATCH 07/22] new tests for h5 --- tests/data/xmdf/withMesh/data.h5 | Bin 0 -> 21688 bytes tests/data/xmdf/withMesh/mesh.h5 | Bin 0 -> 9900 bytes tests/test_xmdf.cpp | 86 +++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 tests/data/xmdf/withMesh/data.h5 create mode 100644 tests/data/xmdf/withMesh/mesh.h5 diff --git a/tests/data/xmdf/withMesh/data.h5 b/tests/data/xmdf/withMesh/data.h5 new file mode 100644 index 0000000000000000000000000000000000000000..51ebdc1408497ad493ee6ee9fbdd0c511d8ec6fe GIT binary patch literal 21688 zcmeHPJ5Ll*6h5;HxPlKJCJ=)$%yP`#Sga&6$~R&ONZ0=;=FIeYP4f z#9~kZwcz*}ecGh3mfV_WkrXAk%>w0DB0Axy-mtET%Ij4B7)-h3!`@y{k~|*A)C|5< z>QtNyB>t}uNc46M;DU!})g2VClb%r)deXD$d}cP!`M&XqjGKIs%TR%zAI!|;$ET;T zi1pT`dNZ==Zz8HC$4D=W>F>sIEw8oT97Xcwj)1AZ{5)JB{o(bGDE-AW#!s*Q(NB*B zb{RjqcfZGhD8#6pOM1(CZ|X76tF0k?Abt+77Lg0@<>=Jfo&y8N^cr$>e;0cW#LsDY z_vkELX1b3En9l*ekCsS(c&Pq#ArI=k)jvMvzsr*2lNn45rYGhw!S`<)Hz*S8=RhQQ z4#Y`sxgS%H`8_poMR&|{1jmmmlT0)l`bAP5Ko{|W&IDt+#iqX8-vqe5;Ji9~#ggkM^i zXix`!+BszTavZjJ6Ls2Zuw1v&DLmH`V?&u=@6%Zxe;zAU*gn4Qug<*y ziYln!LSqaXU;63Y%;!4INB2U_x6KE?cktVY?R6ZV<_1Q5lX~T1ZFmHlE0;Zc{nsp=FneAuGmuwQcobBxkm&4^;s`hqj@C)zm&}w(f z7uSR@9@@2%fdv6UKoAfF1cAdspal71?z{#glrP$N&It>U4=g-~{WdJkq*xFT1Ox#= zKoAfFjxYi{=Q*8ZgYuxg2HH0Re@<;lGWQw(!Y(${qVYtY6VMRTF2?irjc!WNQ9e)@ z9Bt0y;=t~PwmA&!_8O)APuqTFU>~IYRkYh-h&qpnF_HDoFWtIdy0mt26kv>M4kohs ziJE?M#r#A+-_Y|7fIpb&%P1v+faxd7cH%X|?=n9(JUTNy$L#XxAMM zkzN+lU+B{E?jGkM&5kw#rvB=;0ziTEhgawOIjhY6`Z?pSj}En@xBT8Q^_b@&@m2(E z_6wU|&vT3YBG^#d+P&li0YN|z5CjAPL7)r}U^~DHttI$wKRmylrVc%q(0v-yuP5P! zUkvu^DclK{C_+qJFQkkD1AP5Kof`A~f?+BD2UreaK zxyKO77i~Pp=GU`m;W=!d)I-Wy5D)|e0YN|z5CqBzft~Z51M}-?yQ=|4o)gfJ?S4J_ U{~RpQ#W*;>p4Y^f!u@)F1G1aC*Z=?k literal 0 HcmV?d00001 diff --git a/tests/data/xmdf/withMesh/mesh.h5 b/tests/data/xmdf/withMesh/mesh.h5 new file mode 100644 index 0000000000000000000000000000000000000000..4688185d6e5e04cadb2b2c15adcbfc6f3d158902 GIT binary patch literal 9900 zcmeHMKTlLa5Z}E6Jy9Z{35uvMF%k+3LPcSL$`J}d6k_P$;(HvI9Czm(Bv?sdft`hg z1qG!VKLCCLDT$u|J4#DqqdRZr_v98{j*I-ieaXGq*`1x8o&0v*%--9Pq2bn+t`8a)+G9wMlSrPtYf*aasqp@q!-){8NW6MoGOQ)5Q#Co7IO>H%E z3wqG+Xk&O_B>iBVb~+{79T2)9I1^U&4~+(uxzVD(m=CCLIF}E+=RvuWD;6St@>MAu zG#$XLM}vDjarhlcvhbYXvKD@~FR*-Sk2PG^+4q2rUr)BYBKUy^7RtFyA)61TGX;P8 z<_4+;y+n4YnsAC837 z1dT$Lhj6ZOKB14}fR5rouizH)HjXjR(P|IG#eu1dEVm@*o8y3r&1b8%IXWv14z>WhrZ)NBDhQd=cfZhlOAJJL2-NQx330 zHs8iC;+SXUA;4>R33&iEX?2ccxG2_&Gbo+l4qOY#b&az5q}Y9svFp<%%l}7Z$7x?@+W=8N| z_RQ_X-P2>l-FIWohWY*Y{q5n@yg$pIZx?cVLE2JB3!&etNZrS{XBGbQ9ppi~=DJE>PCA3`S23U=m0;}dhUum=_5ZhN@) Uyke$Pp11$?*JOQExqGkw7vr-G=Kufz literal 0 HcmV?d00001 diff --git a/tests/test_xmdf.cpp b/tests/test_xmdf.cpp index c275a259..ac8e0528 100644 --- a/tests/test_xmdf.cpp +++ b/tests/test_xmdf.cpp @@ -501,6 +501,92 @@ TEST( MeshXmdfTest, withFinalgroup ) MDAL_CloseMesh( m ); } +TEST( MeshXmdfTest, MeshLoading ) +{ + std::string pathMesh = test_file( "/xmdf/withMesh/mesh.h5" ); + MDAL_MeshH m = MDAL_LoadMesh( pathMesh.c_str() ); + ASSERT_NE( m, nullptr ); + + ASSERT_EQ( 5, MDAL_M_vertexCount( m ) ); + ASSERT_EQ( 2, MDAL_M_faceCount( m ) ); + + double minX, maxX, minY, maxY; + MDAL_M_extent( m, &minX, &maxX, &minY, &maxY ); + + EXPECT_DOUBLE_EQ( 1000, minX ); + EXPECT_DOUBLE_EQ( 3000, maxX ); + EXPECT_DOUBLE_EQ( 2000, minY ); + EXPECT_DOUBLE_EQ( 3000, maxY ); + + EXPECT_EQ( 1, MDAL_M_datasetGroupCount( m ) ); + + MDAL_DatasetGroupH g = MDAL_M_datasetGroup( m, 0 ); + ASSERT_NE( g, nullptr ); + + EXPECT_TRUE( MDAL_G_hasScalarData( g ) ); + + int meta_count = MDAL_G_metadataCount( g ); + ASSERT_EQ( 1, meta_count ); + + const char *name = MDAL_G_name( g ); + EXPECT_EQ( std::string( "Z-Values" ), std::string( name ) ); + + EXPECT_EQ( MDAL_M_datasetGroupCount( m ), 1 ); + + MDAL_DatasetH ds = MDAL_G_dataset( g, 0 ); + + EXPECT_TRUE( MDAL_D_isValid( ds ) ); + + double min, max; + MDAL_D_minimumMaximum( ds, &min, &max ); + + EXPECT_DOUBLE_EQ( 10, min ); + EXPECT_DOUBLE_EQ( 50, max ); +} + +TEST( MeshXmdfTest, DataInSubfolder ) +{ + std::string pathMesh = test_file( "/xmdf/withMesh/mesh.h5" ); + MDAL_MeshH m = MDAL_LoadMesh( pathMesh.c_str() ); + ASSERT_NE( m, nullptr ); + ASSERT_EQ( 1, MDAL_M_datasetGroupCount( m ) ); + + std::string path = test_file( "/xmdf/withMesh/data.h5" ); + EXPECT_TRUE( std::string( MDAL_MeshNames( path.c_str() ) ).empty() ); + MDAL_M_LoadDatasets( m, path.c_str() ); + MDAL_Status s = MDAL_LastStatus(); + EXPECT_EQ( MDAL_Status::None, s ); + + ASSERT_EQ( 3, MDAL_M_datasetGroupCount( m ) ); + + MDAL_DatasetGroupH g = MDAL_M_datasetGroup( m, 1 ); + ASSERT_NE( g, nullptr ); + ASSERT_EQ(std::string("/Datasets/data"), std::string(MDAL_G_name( g ))); + + MDAL_DatasetH ds = MDAL_G_dataset( g, 0 ); + ASSERT_NE( ds, nullptr ); + ASSERT_TRUE(MDAL_D_isValid( ds )); + EXPECT_EQ(5, MDAL_D_valueCount( ds )); + + double min, max; + MDAL_D_minimumMaximum( ds, &min, &max ); + EXPECT_DOUBLE_EQ( 1, min ); + EXPECT_DOUBLE_EQ( 3, max ); + + g = MDAL_M_datasetGroup( m, 2); + ASSERT_NE( g, nullptr ); + ASSERT_EQ(std::string("subgroup"), std::string(MDAL_G_name( g ))); + + ds = MDAL_G_dataset( g, 0 ); + ASSERT_NE( ds, nullptr ); + ASSERT_TRUE(MDAL_D_isValid( ds )); + EXPECT_EQ(5, MDAL_D_valueCount( ds )); + + MDAL_D_minimumMaximum( ds, &min, &max ); + EXPECT_DOUBLE_EQ( 100, min ); + EXPECT_DOUBLE_EQ( 500, max ); +} + int main( int argc, char **argv ) { testing::InitGoogleTest( &argc, argv ); From 26a2cc57901cc19ce6dbefbfdfd23384d6d01df6 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Thu, 31 Oct 2024 20:37:15 +0100 Subject: [PATCH 08/22] add info --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd02dabf..6e9878cf 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ QGIS contains internal copy of MDAL library in following versions: | 3.30.0 | 1.0.2 | | | 3.36.0 | 1.1.0 | Mike21 format support read/write | | 3.38.0 | 1.2.0 | Groundwater / surface water meshes for 3Di format | -| 3.42.0 | 1.3.0 | Fix 2dm format coordinates saving | +| 3.42.0 | 1.3.0 | Fix 2dm format coordinates saving; XMDF loading Dataset Group fix, support for Mesh in XMDF files (as 2DMeshModule) | versions `X.Y.9Z` are development versions or alpha/beta releases (e.g. `0.4.90`, `0.4.91`, ...) From 9b9471422be060dd6d740ca73fe5783e3dc90e4b Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Thu, 31 Oct 2024 20:40:31 +0100 Subject: [PATCH 09/22] style fix --- tests/test_xmdf.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_xmdf.cpp b/tests/test_xmdf.cpp index ac8e0528..9cd608b2 100644 --- a/tests/test_xmdf.cpp +++ b/tests/test_xmdf.cpp @@ -561,26 +561,26 @@ TEST( MeshXmdfTest, DataInSubfolder ) MDAL_DatasetGroupH g = MDAL_M_datasetGroup( m, 1 ); ASSERT_NE( g, nullptr ); - ASSERT_EQ(std::string("/Datasets/data"), std::string(MDAL_G_name( g ))); + ASSERT_EQ( std::string( "/Datasets/data" ), std::string( MDAL_G_name( g ) ) ); MDAL_DatasetH ds = MDAL_G_dataset( g, 0 ); ASSERT_NE( ds, nullptr ); - ASSERT_TRUE(MDAL_D_isValid( ds )); - EXPECT_EQ(5, MDAL_D_valueCount( ds )); + ASSERT_TRUE( MDAL_D_isValid( ds ) ); + EXPECT_EQ( 5, MDAL_D_valueCount( ds ) ); double min, max; MDAL_D_minimumMaximum( ds, &min, &max ); EXPECT_DOUBLE_EQ( 1, min ); EXPECT_DOUBLE_EQ( 3, max ); - g = MDAL_M_datasetGroup( m, 2); + g = MDAL_M_datasetGroup( m, 2 ); ASSERT_NE( g, nullptr ); - ASSERT_EQ(std::string("subgroup"), std::string(MDAL_G_name( g ))); + ASSERT_EQ( std::string( "subgroup" ), std::string( MDAL_G_name( g ) ) ); ds = MDAL_G_dataset( g, 0 ); ASSERT_NE( ds, nullptr ); - ASSERT_TRUE(MDAL_D_isValid( ds )); - EXPECT_EQ(5, MDAL_D_valueCount( ds )); + ASSERT_TRUE( MDAL_D_isValid( ds ) ); + EXPECT_EQ( 5, MDAL_D_valueCount( ds ) ); MDAL_D_minimumMaximum( ds, &min, &max ); EXPECT_DOUBLE_EQ( 100, min ); From b67f8eb8e0828add5b542f45f8de7a8b3e673eee Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Tue, 5 Nov 2024 12:56:53 +0100 Subject: [PATCH 10/22] use buildUri and findMeshesNames to identify existing groups with Mesh Data ... in the same way UGRID driver does that --- mdal/frmts/mdal_xmdf.cpp | 96 +++++++++++++++++++++++++++++----------- mdal/frmts/mdal_xmdf.hpp | 5 +++ 2 files changed, 76 insertions(+), 25 deletions(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index d87617d5..9c579e0a 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -357,35 +357,71 @@ bool MDAL::DriverXmdf::canReadMesh( const std::string &uri ) return false; } - std::vector rootGroups = file.groups(); - if ( rootGroups.empty() || !MDAL::contains( rootGroups, "2DMeshModule" ) ) + std::vector meshPaths = meshGroupPaths( file ); + + return !meshPaths.empty(); +} + +std::string MDAL::DriverXmdf::buildUri( const std::string &meshFile ) +{ + mDatFile = meshFile; + + std::vector meshNames = findMeshesNames(); + + return MDAL::buildAndMergeMeshUris( meshFile, meshNames, name() ); +} + +std::vector MDAL::DriverXmdf::findMeshesNames() const +{ + std::vector meshesInFile; + + HdfFile file( mDatFile, HdfFile::ReadOnly ); + if ( !file.isValid() ) { - MDAL::Log::debug( "Mesh from `" + mDatFile + "` does not contain group `2DMeshModule`." ); - return false; + return meshesInFile; } - HdfGroup meshModuleGroup = file.group( "2DMeshModule" ); + meshesInFile = meshGroupPaths( file ); - std::vector gGroupNames = meshModuleGroup.groups(); + return meshesInFile; +} - HdfGroup firstGroupMeshModule = meshModuleGroup.group( gGroupNames[0] ); +std::vector MDAL::DriverXmdf::meshGroupPaths( const HdfFile &file ) const +{ + std::vector meshPaths; - if ( !firstGroupMeshModule.isValid() ) + std::vector rootGroups = file.groups(); + + for ( const std::string &groupName : rootGroups ) { - MDAL::Log::debug( "Mesh Group module `" + firstGroupMeshModule.name() + "` is not valid." ); - return false; + HdfGroup g = file.group( groupName ); + std::vector paths = meshGroupPaths( g ); + meshPaths.insert( meshPaths.end(), paths.begin(), paths.end() ); } - std::vector gDataNames = firstGroupMeshModule.groups(); + return meshPaths; +} + +std::vector MDAL::DriverXmdf::meshGroupPaths( const HdfGroup &group ) const +{ + std::vector meshPaths; - if ( !MDAL::contains( gDataNames, "Nodes" ) || - !MDAL::contains( gDataNames, "Elements" ) ) + std::vector gDataNames = group.groups(); + + if ( MDAL::contains( gDataNames, "Nodes" ) || + MDAL::contains( gDataNames, "Elements" ) ) { - MDAL::Log::debug( "Mesh Group module `" + firstGroupMeshModule.name() + "` does not contain `Nodes` and `Elements` groups." ); - return false; + meshPaths.push_back( group.name() ); } - return true; + for ( const std::string &groupName : gDataNames ) + { + HdfGroup g = group.group( groupName ); + std::vector paths = meshGroupPaths( g ); + meshPaths.insert( meshPaths.end(), paths.begin(), paths.end() ); + } + + return meshPaths; } std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFile, const std::string &meshName ) @@ -408,22 +444,32 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil return nullptr; } - std::vector rootGroups = file.groups(); - if ( rootGroups.empty() ) + std::vector meshNames = findMeshesNames(); + + if ( meshNames.empty() ) { - MDAL::Log::error( MDAL_Status::Err_UnknownFormat, name(), "Expecting at least one root group for the mesh data" ); + MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), "No meshes found in file" + mDatFile ); return nullptr; } - HdfGroup meshModuleGroup = file.group( "2DMeshModule" ); + std::string meshNameToLoad = meshName; - std::vector gGroupNames = meshModuleGroup.groups(); + if ( meshNameToLoad.empty() ) + { + meshNameToLoad = meshNames[0]; + } + + if ( !MDAL::contains( meshNames, meshNameToLoad ) ) + { + MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), "No meshes with name " + meshNameToLoad + "found in file" + mDatFile ); + return nullptr; + } - HdfGroup firstGroupMeshModule = meshModuleGroup.group( gGroupNames[0] ); + HdfGroup groupMeshModule = file.group( meshNameToLoad ); - std::vector gDataNames = firstGroupMeshModule.groups(); + std::vector gDataNames = groupMeshModule.groups(); - HdfGroup gNodes = firstGroupMeshModule.group( "Nodes" ); + HdfGroup gNodes = groupMeshModule.group( "Nodes" ); std::vector namesNodes = gNodes.datasets(); HdfDataset nodes = gNodes.dataset( namesNodes[0] ); @@ -456,7 +502,7 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil nodesData.clear(); - HdfGroup gElements = firstGroupMeshModule.group( "Elements" ); + HdfGroup gElements = groupMeshModule.group( "Elements" ); std::vector namesElements = gElements.datasets(); HdfDataset elements = gElements.dataset( namesElements[0] ); diff --git a/mdal/frmts/mdal_xmdf.hpp b/mdal/frmts/mdal_xmdf.hpp index 1ca88815..3163031b 100644 --- a/mdal/frmts/mdal_xmdf.hpp +++ b/mdal/frmts/mdal_xmdf.hpp @@ -114,6 +114,11 @@ namespace MDAL size_t vertexCount, size_t faceCount ) const; + std::string buildUri( const std::string &meshFile ) override; + std::vector findMeshesNames() const; + + std::vector meshGroupPaths( const HdfGroup &group ) const; + std::vector meshGroupPaths( const HdfFile &file ) const; }; } // namespace MDAL From fc3af0549ea8f3c1de7d1ce49dd38a2a5f4ec7ce Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Tue, 5 Nov 2024 12:57:25 +0100 Subject: [PATCH 11/22] fix test data --- tests/data/xmdf/withMesh/mesh.h5 | Bin 9900 -> 9900 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/tests/data/xmdf/withMesh/mesh.h5 b/tests/data/xmdf/withMesh/mesh.h5 index 4688185d6e5e04cadb2b2c15adcbfc6f3d158902..48a7ad5c6e1c699dc42f18c159bf0a7d183a1cfc 100644 GIT binary patch delta 22 dcmZ4EyT*5d2qVKr(R3LW76t}}%?&a-TmVZV1#SQU delta 22 ccmZ4EyT*5d2qWW0(R3M>|3I+0K}LrQ0BG+CX8-^I From 9c08aaead79c9ad09a324091c101dd18448d17a8 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Tue, 5 Nov 2024 13:12:39 +0100 Subject: [PATCH 12/22] file with multiple mesh datasets --- tests/data/xmdf/withMesh/multiple_meshes.h5 | Bin 0 -> 32084 bytes tests/test_xmdf.cpp | 58 ++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/data/xmdf/withMesh/multiple_meshes.h5 diff --git a/tests/data/xmdf/withMesh/multiple_meshes.h5 b/tests/data/xmdf/withMesh/multiple_meshes.h5 new file mode 100644 index 0000000000000000000000000000000000000000..757669ab87512090fedc7c15b4147d8a3ec25fcd GIT binary patch literal 32084 zcmeHQL2MLN7@lnxtyp5gCLp3tA`*-n(;x?;7#G}P2?YwQP?gwLcWG;u-O_GNF&H`Y zP?H`!aPZIrhaS{$@W26+9-GLa2VyvKz@!Hb960n~42jM^|NkvJKb_8QJ6*OrZ^+D> z|II)D```Ee_rLf4H(h@0N*&pZ;zM=Gyb_c!s~1Tst-DFnJY5A{%mf0tSxkhJ{>-}u?t zygXm*TAA+sKEA_P{of7*248_sm zf&5@D+c%KU^j#Vs$jAfuSJ*xHgVHl6PNrhka~AB*7Q2N!ZO20*@OH_6bB69mdxbBt zXJrj`$m5x}R_1d%x5JWpoB5#M4UxYf1x|>V#Q`s0>sL%C0GRNFmH7FAp69uQ5$WGS ze&Ep-=I;ngF(YR~A)x(0Qndd`><5+kxKJ3)4Ce=m*)cb(Gnc)X%@>()a!wR7?h`k4 zoJM|-AEDo%-$5Sxfmq28>=nBOzqVt%XHqW$etw|$Mdq83{>^^C@}19mr5Y+~2xvcm z@%d-5AK+2ypU7Ba%6=eT@&g@WwY`|XE6m->IdpH3+JYo*6VFXw?{ zFn64_J-J^>>3rR}zvayH>7J~NQlj@c_ry>4v;h=klM)gXdvk2ed4~?RKg+7#CNsNO zg3XCs%WZPcZ_nB$n@Ve?)}0ry^exyzRy6pLI)@q0EW<{B{s{9-u| zY0+DDfJCf4BhQL`m)tw_kB+i;R=V|zrR#53g6#L}O(a-wx0J8HeVCVg z=%e{DJ}gk6)H%SnUmSE=@-d#olP+6{FZUtS(;smPzdkGT6v%5m%+C{&&s67Ms%Dk}r^r8?uJ_&c4zfl{J*-NyIy9^Tbh;qP<8z{)Ac90mb{ zfI+|@U=Ub$1Q5rZl9KedH#8Q~L1P{rny!Aoc}ZqIwkr>p^7tx!=fLZeC*K<^y${ai zQ_QdLdOzt|o;gCfm9{UN5F60 zbVK3?K%iFN((3p{P`|?N4Xq>S&~)|vYM1mYuY)V^SM<%I{&p~tbc;8aDiJX8-6{c# z7`ygQ811@M+!EtxPe}Oq#dmew6n?;#a^n*Jg+6*eBP8`2R?NQC@$A^p@j_-im!(P` z8O~+xv)R$H;X=Md(;p-W0+>%D-gjB@PZo!=qb%m!aB+x)x=#+}3-siZ(Zcu$Wqg(` zda}@Ndqs|45;U)x>E}0LuYPh&eq$n_{TA#qe$-oEZSSzZq?fH?D#$L=eJsk@WyO#- z6r;9FTWU9R%v;T{e-kFiE{mtQ{0^@ghKdLR+Afn)@BJsd0MzO`lqKm8?NYv3r+C}J zP+kPI{bGDwQVSA{?<(6XtP09+opMv`_O2A9zeDL3e+zvyKjtgxPgxo8&7EfYUYb+P zlczuT@-3ZXx?S?&*Ap`TfV^wxneXP8oYwm_XdG)l%Qa}L_lg+()&&9W2hfimOMgM3 zwfYW4_t&6!D)uG9+lT6vc&d%6yJ>kmb-8`0E8=%NFO?DKU+2Zols$^{ZKdrC|BLnp zU46WKB9wio?k~96Fm6V=5hGZ6Kfk$O<`00RR{KzT{u0!$^uCj(tM6A=SG5myQ{e^N zOu8}xW_`CZK2d+F{S(HiyK3Enaa5LFYlh8leW%w=*oT5%)3W}9K02PUX2lv*fX4BW zOpt)1-*2`zC>*PnLPq$uS73@`OVqV

AKk?u@rqh%aHijs0G|1&n@- zxRqDR6Dr6q=f7iK`^hWjE=I@h_TPQair{%EKgfO;bKF?yHxX(& zQ&k56ZNEuDWp>yLPp$UbGJ{<1q?B*gW8QW!lotVQzgYKV#IJ!Hc&vd)Tq~yb|&&WIl^5PTBw_Ea=s^4qS zI5x>YpQ8Q;x%#b-(JWj9v>!k}%1M7gX|>vK)BQClZjAkx@b=s0R<+;uP~ipKkhaOq z!YFb~N(fZizVN?jZ_w563)~B3zisYYZa<8hrZuC5fS=!-mH7kEsMUU(p1%b3E4{y_ z>FWE{;;Q!Bc1u43UM8&!0kgiV45z4aY5#!Ph?BEk0ova ceRMn{B=s6jjK=Yx#DRdLj%zj?03lWAe?76#%K!iX literal 0 HcmV?d00001 diff --git a/tests/test_xmdf.cpp b/tests/test_xmdf.cpp index 9cd608b2..18de75ec 100644 --- a/tests/test_xmdf.cpp +++ b/tests/test_xmdf.cpp @@ -587,6 +587,64 @@ TEST( MeshXmdfTest, DataInSubfolder ) EXPECT_DOUBLE_EQ( 500, max ); } +TEST( MeshXmdfTest, MultipleMeshes ) +{ + // dataset without mesh + std::string path = test_file( "/xmdf/withMesh/data.h5" ); + EXPECT_EQ( std::string( MDAL_MeshNames( path.c_str() ) ), std::string( "" ) ); + MDAL_MeshH m = MDAL_LoadMesh( path.c_str() ); + ASSERT_EQ( m, nullptr ); + + // test that all 4 meshes are found + path = test_file( "/xmdf/withMesh/multiple_meshes.h5" ); + EXPECT_EQ( MDAL_MeshNames( path.c_str() ), + "XMDF:\"" + path + "\":/2DMeshModule/triangle_and_quad;;" + + "XMDF:\"" + path + "\":/AnotherGroup/2DMeshModule/triangle_and_quad;;" + + "XMDF:\"" + path + "\":/OtherModuleWithMesh/t_q;;" + + "XMDF:\"" + path + "\":/YetAnotherGroup/ModuleWithMesh/t_q" ); + + // default mesh can be loaded + m = MDAL_LoadMesh( path.c_str() ); + ASSERT_NE( m, nullptr ); + + // load specific mesh and test extent to validate correct mesh was loaded + std::string uri = "\"" + path + "\":/2DMeshModule/triangle_and_quad"; + m = MDAL_LoadMesh( uri.c_str() ); + ASSERT_NE( m, nullptr ); + + double minX, maxX, minY, maxY; + MDAL_M_extent( m, &minX, &maxX, &minY, &maxY ); + + EXPECT_DOUBLE_EQ( 1000, minX ); + EXPECT_DOUBLE_EQ( 3000, maxX ); + EXPECT_DOUBLE_EQ( 2000, minY ); + EXPECT_DOUBLE_EQ( 3000, maxY ); + + // load another mesh + uri = "\"" + path + "\":/AnotherGroup/2DMeshModule/triangle_and_quad"; + m = MDAL_LoadMesh( uri.c_str() ); + ASSERT_NE( m, nullptr ); + + MDAL_M_extent( m, &minX, &maxX, &minY, &maxY ); + + EXPECT_DOUBLE_EQ( 10, minX ); + EXPECT_DOUBLE_EQ( 30, maxX ); + EXPECT_DOUBLE_EQ( 20, minY ); + EXPECT_DOUBLE_EQ( 30, maxY ); + + // load another mesh + uri = "\"" + path + "\":/YetAnotherGroup/ModuleWithMesh/t_q"; + m = MDAL_LoadMesh( uri.c_str() ); + ASSERT_NE( m, nullptr ); + + MDAL_M_extent( m, &minX, &maxX, &minY, &maxY ); + + EXPECT_DOUBLE_EQ( 1, minX ); + EXPECT_DOUBLE_EQ( 3, maxX ); + EXPECT_DOUBLE_EQ( 2, minY ); + EXPECT_DOUBLE_EQ( 3, maxY ); +} + int main( int argc, char **argv ) { testing::InitGoogleTest( &argc, argv ); From cf2123189b1f3f665689db1c0843ad610f9a0b3e Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Tue, 5 Nov 2024 16:56:40 +0100 Subject: [PATCH 13/22] add h5 as extension for XMDF --- mdal/frmts/mdal_xmdf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 9c579e0a..4554810c 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -92,7 +92,7 @@ size_t MDAL::XmdfDataset::activeData( size_t indexStart, size_t count, int *buff MDAL::DriverXmdf::DriverXmdf() : Driver( "XMDF", "TUFLOW XMDF", - "*.xmdf", + "*.xmdf;;*.h5", Capability::ReadDatasets | Capability::ReadMesh ) { } From e6e280aa25518f1272614f9290090f3773d7e7ba Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Nov 2024 09:21:08 +0100 Subject: [PATCH 14/22] only store faces that have more than 2 vertices --- mdal/frmts/mdal_xmdf.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 4554810c..39eeed3e 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -520,28 +520,38 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil i = 0; while ( i < facesData.size() ) { - Face &face = faces[currentFaceIndex]; + std::vector tempFace; for ( int j = 0; j < elementsRowsDims; j++ ) { int vertexIndex = facesData[i]; if ( vertexIndex > 0 ) { // XMDF is 1-based, MDAL is 0-based - face.push_back( facesData[i] - 1 ); + tempFace.push_back( facesData[i] - 1 ); } + i++; + } + + // only store faces with more than 2 vertices + if (tempFace.size() > 2) + { + Face &face = faces[currentFaceIndex]; + std::copy( tempFace.begin(), tempFace.end(), std::back_inserter( face ) ); - if ( j + 1 > maxVerticesPerFace ) + if ( tempFace.size() > maxVerticesPerFace ) { - maxVerticesPerFace = j + 1; + maxVerticesPerFace = tempFace.size(); } - i++; + currentFaceIndex++; } - currentFaceIndex++; } facesData.clear(); + // copy only the faces that have been properly filled + faces = Faces( faces.begin(), faces.begin() + currentFaceIndex ); + // create the mesh and set the required data std::unique_ptr< MemoryMesh > mesh( new MemoryMesh( From 7fa4a2b111ed1dd30e4007e8387cc892de0a4960 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Nov 2024 09:21:17 +0100 Subject: [PATCH 15/22] add info --- docs/source/drivers/xmdf.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/source/drivers/xmdf.rst b/docs/source/drivers/xmdf.rst index 851bc198..da964089 100644 --- a/docs/source/drivers/xmdf.rst +++ b/docs/source/drivers/xmdf.rst @@ -10,5 +10,8 @@ XMDF -- eXtensible Model Data Format MDAL supports reading of the XMDF format generated by TUFLOW_, HYDRO_AS-2D_ and other hydraulic modelling software applications. +Since 1.3 MDAL supports reading mesh stored in XMDF format according to specification - http://xmdf.aquaveo.com/doc2.2/html/modules.html. + .. _TUFLOW: https://www.tuflow.com/ .. _HYDRO_AS-2D : https://www.hydroas-2d.com/ +.. _Mesh Format: http://xmdf.aquaveo.com/doc2.2/html/group__d2d4d1d.html \ No newline at end of file From 6376cbfe6d43d9f072ace98ac53592f5874dd3a3 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Nov 2024 11:23:55 +0100 Subject: [PATCH 16/22] fix style --- mdal/frmts/mdal_xmdf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 39eeed3e..6f85aea2 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -533,7 +533,7 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil } // only store faces with more than 2 vertices - if (tempFace.size() > 2) + if ( tempFace.size() > 2 ) { Face &face = faces[currentFaceIndex]; std::copy( tempFace.begin(), tempFace.end(), std::back_inserter( face ) ); From 178bdc7a24027235588201dabbd02d8a2bb9e20f Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Nov 2024 14:04:17 +0100 Subject: [PATCH 17/22] Update mdal/frmts/mdal_xmdf.cpp fix message Co-authored-by: Stefanos Natsis --- mdal/frmts/mdal_xmdf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 6f85aea2..de1a06e4 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -461,7 +461,7 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil if ( !MDAL::contains( meshNames, meshNameToLoad ) ) { - MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), "No meshes with name " + meshNameToLoad + "found in file" + mDatFile ); + MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), "No meshes with name " + meshNameToLoad + " found in file " + mDatFile ); return nullptr; } From ebd7b9c953b75334ff01dc7a59870121b1913ce4 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Nov 2024 14:04:33 +0100 Subject: [PATCH 18/22] Update mdal/frmts/mdal_xmdf.cpp fix messages Co-authored-by: Stefanos Natsis --- mdal/frmts/mdal_xmdf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index de1a06e4..0c4a7e63 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -448,7 +448,7 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil if ( meshNames.empty() ) { - MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), "No meshes found in file" + mDatFile ); + MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), "No meshes found in file " + mDatFile ); return nullptr; } From 223bf1ec6547e302290c9ce344b69d75ed9f96fa Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Nov 2024 14:11:00 +0100 Subject: [PATCH 19/22] vertexDims size check --- mdal/frmts/mdal_xmdf.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 0c4a7e63..bd31ac95 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -478,6 +478,12 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil hsize_t nodesRows = nodesDims[0]; size_t vertexDims = nodesDims[1]; + if ( vertexDims < 2 || vertexDims > 3 ) + { + MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), "Vertices have unsupported number of dimensions " + std::to_string(vertexDims) + " only 2 (X,Y) or 3 (X, Y, Z) dimensions are allowed." ); + return nullptr; + } + std::vector nodesData = nodes.readArrayDouble(); Vertices vertices( nodesRows ); From 65a78325bc684c9b2afd2225a5eca3eb1511dde0 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Nov 2024 14:11:12 +0100 Subject: [PATCH 20/22] add empty line --- mdal/frmts/mdal_xmdf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index bd31ac95..10b0f13f 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -579,4 +579,4 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil addVertexScalarDatasetGroup( mesh.get(), values, "Z-Values" ); return mesh; -} \ No newline at end of file +} From f29fe69fdc3a8d8e85e1e4517906c63e83f24ee4 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Nov 2024 14:14:06 +0100 Subject: [PATCH 21/22] fix style --- mdal/frmts/mdal_xmdf.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 10b0f13f..45f5dae5 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -480,10 +480,11 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil if ( vertexDims < 2 || vertexDims > 3 ) { - MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), "Vertices have unsupported number of dimensions " + std::to_string(vertexDims) + " only 2 (X,Y) or 3 (X, Y, Z) dimensions are allowed." ); + MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), "Vertices have unsupported number of dimensions " + std::to_string( vertexDims ) + " only 2 (X,Y) or 3 (X, Y, Z) dimensions are allowed." ); return nullptr; } + std::vector nodesData = nodes.readArrayDouble(); Vertices vertices( nodesRows ); From 08aeb689926bd50ec4677d5a2b54546b0b425287 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Nov 2024 14:14:26 +0100 Subject: [PATCH 22/22] drop empty line --- mdal/frmts/mdal_xmdf.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/mdal/frmts/mdal_xmdf.cpp b/mdal/frmts/mdal_xmdf.cpp index 45f5dae5..340722b9 100644 --- a/mdal/frmts/mdal_xmdf.cpp +++ b/mdal/frmts/mdal_xmdf.cpp @@ -484,7 +484,6 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverXmdf::load( const std::string &meshFil return nullptr; } - std::vector nodesData = nodes.readArrayDouble(); Vertices vertices( nodesRows );