Skip to content
Permalink
Browse files
fix maximum vertices count per face for mesh editing (#44759)
fix writing UGRID format (mesh layer)
  • Loading branch information
vcloarec committed Aug 19, 2021
1 parent 078accb commit 2cdc666fb5d0213313af63084679075f620a7a3b
@@ -66,7 +66,8 @@ Constructs driver metadata with selected capabilities
const QString &description,
const MeshDriverCapabilities &capabilities,
const QString &writeDatasetOnFileSuffix,
const QString &writeMeshFrameOnFileSuffix );
const QString &writeMeshFrameOnFileSuffix,
int maxVerticesPerface );
%Docstring
Constructs driver metadata with selected capabilities

@@ -75,6 +76,7 @@ Constructs driver metadata with selected capabilities
:param capabilities: driver's capabilities
:param writeDatasetOnFileSuffix: suffix used to write datasets on file
:param writeMeshFrameOnFileSuffix: suffix used to write mesh frame on file
:param maxVerticesPerface: maximum vertices count per face supported by the driver

.. versionadded:: 3.22
%End
@@ -103,6 +105,13 @@ Returns the suffix used to write datasets on file
%Docstring
Returns the suffix used to write mesh on file

.. versionadded:: 3.22
%End

int maximumVerticesCountPerFace() const;
%Docstring
Returns the maximum number of vertices per face supported by the driver

.. versionadded:: 3.22
%End

@@ -359,12 +359,14 @@ QgsMeshDriverMetadata::QgsMeshDriverMetadata( const QString &name,
const QString &description,
const MeshDriverCapabilities &capabilities,
const QString &writeDatasetOnfileSuffix,
const QString &writeMeshFrameOnFileSuffix )
const QString &writeMeshFrameOnFileSuffix,
int maxVerticesPerface )
: mName( name )
, mDescription( description )
, mCapabilities( capabilities )
, mWriteDatasetOnFileSuffix( writeDatasetOnfileSuffix )
, mWriteMeshFrameOnFileSuffix( ( writeMeshFrameOnFileSuffix ) )
, mMaxVerticesPerFace( maxVerticesPerface )
{
}

@@ -392,3 +394,8 @@ QString QgsMeshDriverMetadata::writeMeshFrameOnFileSuffix() const
{
return mWriteMeshFrameOnFileSuffix;
}

int QgsMeshDriverMetadata::maximumVerticesCountPerFace() const
{
return mMaxVerticesPerFace;
}
@@ -101,14 +101,16 @@ class CORE_EXPORT QgsMeshDriverMetadata
* \param capabilities driver's capabilities
* \param writeDatasetOnFileSuffix suffix used to write datasets on file
* \param writeMeshFrameOnFileSuffix suffix used to write mesh frame on file
* \param maxVerticesPerface maximum vertices count per face supported by the driver
*
* \since QGIS 3.22
*/
QgsMeshDriverMetadata( const QString &name,
const QString &description,
const MeshDriverCapabilities &capabilities,
const QString &writeDatasetOnFileSuffix,
const QString &writeMeshFrameOnFileSuffix );
const QString &writeMeshFrameOnFileSuffix,
int maxVerticesPerface );

/**
* Returns the capabilities for this driver.
@@ -137,12 +139,20 @@ class CORE_EXPORT QgsMeshDriverMetadata
*/
QString writeMeshFrameOnFileSuffix() const;

/**
* Returns the maximum number of vertices per face supported by the driver
*
* \since QGIS 3.22
*/
int maximumVerticesCountPerFace() const;

private:
QString mName;
QString mDescription;
MeshDriverCapabilities mCapabilities;
QString mWriteDatasetOnFileSuffix;
QString mWriteMeshFrameOnFileSuffix;
int mMaxVerticesPerFace = -1;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMeshDriverMetadata::MeshDriverCapabilities )
@@ -224,10 +224,7 @@ QgsRectangle QgsMdalProvider::extent() const

int QgsMdalProvider::maximumVerticesCountPerFace() const
{
if ( !mMeshH )
return 0;

return MDAL_M_faceVerticesMaximumCount( mMeshH );
return driverMetadata().maximumVerticesCountPerFace();
}

QgsMeshDriverMetadata QgsMdalProvider::driverMetadata() const
@@ -240,6 +237,7 @@ QgsMeshDriverMetadata QgsMdalProvider::driverMetadata() const
QString longName = MDAL_DR_longName( mdalDriver );
QString writeDatasetSuffix = MDAL_DR_writeDatasetsSuffix( mdalDriver );
QString writeMeshFrameSuffix = MDAL_DR_saveMeshSuffix( mdalDriver );
int maxVerticesPerFace = MDAL_DR_faceVerticesMaximumCount( mdalDriver );

QgsMeshDriverMetadata::MeshDriverCapabilities capabilities;
bool hasSaveFaceDatasetsCapability = MDAL_DR_writeDatasetsCapability( mdalDriver, MDAL_DataLocation::DataOnFaces );
@@ -254,7 +252,7 @@ QgsMeshDriverMetadata QgsMdalProvider::driverMetadata() const
bool hasMeshSaveCapability = MDAL_DR_saveMeshCapability( mdalDriver );
if ( hasMeshSaveCapability )
capabilities |= QgsMeshDriverMetadata::CanWriteMeshData;
const QgsMeshDriverMetadata meta( name, longName, capabilities, writeDatasetSuffix, writeMeshFrameSuffix );
const QgsMeshDriverMetadata meta( name, longName, capabilities, writeDatasetSuffix, writeMeshFrameSuffix, maxVerticesPerFace );

return meta;
}
@@ -1204,6 +1202,7 @@ QList<QgsMeshDriverMetadata> QgsMdalProviderMetadata::meshDriversMetadata()
QString longName = MDAL_DR_longName( mdalDriver );
QString writeDatasetSuffix = MDAL_DR_writeDatasetsSuffix( mdalDriver );
QString writeMeshFrameSuffix = MDAL_DR_saveMeshSuffix( mdalDriver );
int maxVerticesPerFace = MDAL_DR_faceVerticesMaximumCount( mdalDriver );

QgsMeshDriverMetadata::MeshDriverCapabilities capabilities;
bool hasSaveFaceDatasetsCapability = MDAL_DR_writeDatasetsCapability( mdalDriver, MDAL_DataLocation::DataOnFaces );
@@ -1218,7 +1217,7 @@ QList<QgsMeshDriverMetadata> QgsMdalProviderMetadata::meshDriversMetadata()
bool hasMeshSaveCapability = MDAL_DR_saveMeshCapability( mdalDriver );
if ( hasMeshSaveCapability )
capabilities |= QgsMeshDriverMetadata::CanWriteMeshData;
const QgsMeshDriverMetadata meta( name, longName, capabilities, writeDatasetSuffix, writeMeshFrameSuffix );
const QgsMeshDriverMetadata meta( name, longName, capabilities, writeDatasetSuffix, writeMeshFrameSuffix, maxVerticesPerFace );
ret.push_back( meta );
}
return ret;
@@ -1249,7 +1249,7 @@ void TestQgsMeshEditor::meshEditorFromMeshLayer_quadTriangle()
centroid = meshLayerQuadTriangle->snapOnElement( QgsMesh::Face, QgsPoint( 2050, 2800, 0 ), 10 );
QVERIFY( centroid.compare( QgsPointXY( 2166.6666666, 2422.22222222 ), 1e-6 ) ); //same face

QVERIFY( !editor->canBeMerged( 2, 3 ) ); //leads to 5 vertices per face, limited to 4
QVERIFY( editor->canBeMerged( 2, 3 ) );

//split
QVERIFY( editor->faceCanBeSplit( 8 ) );

0 comments on commit 2cdc666

Please sign in to comment.