Skip to content

Commit

Permalink
optimisation and QGIS version update
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec authored and github-actions[bot] committed Jan 21, 2023
1 parent d3ce7d5 commit e104f1b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/core/mesh/qgsmesheditor.cpp
Expand Up @@ -325,6 +325,8 @@ bool QgsMeshEditor::faceCanBeAddedWithNewVertices( const QList<int> &verticesInd
int index = face.at( i );
if ( index == -1 )
{
if ( newVertPos >= newVertices.count() )
return false;
allVertices.append( newVertices.at( newVertPos++ ) );
continue;
}
Expand Down Expand Up @@ -733,10 +735,10 @@ QList<int> QgsMeshEditor::prepareFaceWithNewVertices( const QList<int> &face, co
if ( error.errorType != Qgis::MeshEditingErrorType::NoError )
return face;

int direction = 0;
error = QgsTopologicalMesh::checkTopologyOfVerticesAsFace( vertices, direction );
bool clockwise = false;
error = QgsTopologicalMesh::checkTopologyOfVerticesAsFace( vertices, clockwise );

if ( direction > 0 && error.errorType == Qgis::MeshEditingErrorType::NoError )
if ( clockwise && error.errorType == Qgis::MeshEditingErrorType::NoError )
{

QList<int> newFace = face;
Expand Down
4 changes: 2 additions & 2 deletions src/core/mesh/qgsmesheditor.h
Expand Up @@ -116,7 +116,7 @@ class CORE_EXPORT QgsMeshEditor : public QObject
* or the value -1 if the vertex is not existing for now in the mesh. The positions of new vertices are stored in \a newVertices
* sorted by their positions in the face.
*
* \since QGIS 3.28
* \since QGIS 3.30
*/
bool faceCanBeAddedWithNewVertices( const QList<int> &verticesIndex, const QList<QgsMeshVertex> &newVertices ) const; SIP_SKIP

Expand All @@ -138,7 +138,7 @@ class CORE_EXPORT QgsMeshEditor : public QObject
* or the value -1 if the vertex is not existing for now in the mesh. The positions of new vertices are stored in \a newVertices
* sorted by their positions in the face.
*
* \since QGIS 3.28
* \since QGIS 3.30
*/
QgsMeshEditingError addFaceWithNewVertices( const QList<int> &vertexIndexes, const QList<QgsMeshVertex> &newVertices ); SIP_SKIP

Expand Down
26 changes: 17 additions & 9 deletions src/core/mesh/qgstopologicalmesh.cpp
Expand Up @@ -517,7 +517,7 @@ QgsMeshVertexCirculator QgsTopologicalMesh::vertexCirculator( int vertexIndex )
return QgsMeshVertexCirculator( *this, vertexIndex );
}

QSet<int> QgsTopologicalMesh::concernedFacesBy( const QList<int> faceIndexes ) const
QSet<int> QgsTopologicalMesh::concernedFacesBy( const QList<int> &faceIndexes ) const
{
QSet<int> faces;
for ( const int faceIndex : faceIndexes )
Expand Down Expand Up @@ -635,10 +635,10 @@ QList<int> QgsTopologicalMesh::freeVerticesIndexes() const
return QList<int>( mFreeVertices.begin(), mFreeVertices.end() );
}

QgsMeshEditingError QgsTopologicalMesh::checkTopologyOfVerticesAsFace( const QVector<QgsMeshVertex> &vertices, int &direction )
QgsMeshEditingError QgsTopologicalMesh::checkTopologyOfVerticesAsFace( const QVector<QgsMeshVertex> &vertices, bool &clockwise )
{
int size = vertices.size();
direction = 0;
int direction = 0;
for ( int i = 0; i < size; ++i )
{
int iv0 = i;
Expand All @@ -660,13 +660,21 @@ QgsMeshEditingError QgsTopologicalMesh::checkTopologyOfVerticesAsFace( const QVe

double crossProd = crossProduct( v1, v0, v2 ); //if cross product>0, we have two edges clockwise
if ( direction != 0 && crossProd * direction < 0 ) // We have a convex face or a (partially) flat face
{
clockwise = direction > 0;
return QgsMeshEditingError( Qgis::MeshEditingErrorType::InvalidFace, -1 );
}
else if ( crossProd == 0 )
{
clockwise = direction > 0;
return QgsMeshEditingError( Qgis::MeshEditingErrorType::FlatFace, -1 );
else if ( direction == 0 && crossProd != 0 )
}
else if ( direction == 0 )
direction = crossProd / std::fabs( crossProd );
}

clockwise = direction > 0;

return QgsMeshEditingError( Qgis::MeshEditingErrorType::NoError, -1 );
}

Expand All @@ -689,12 +697,12 @@ QgsMeshEditingError QgsTopologicalMesh::counterClockwiseFaces( QgsMeshFace &face
vertices[i] = mesh->vertices.at( face[i] );
}

int direction = 0;
QgsMeshEditingError error = QgsTopologicalMesh::checkTopologyOfVerticesAsFace( vertices, direction );
bool clockwise = false;
QgsMeshEditingError error = QgsTopologicalMesh::checkTopologyOfVerticesAsFace( vertices, clockwise );
if ( error != QgsMeshEditingError() )
return error;

if ( direction > 0 )// clockwise --> reverse the order of the index;
if ( clockwise > 0 )// clockwise --> reverse the order of the index;
{
for ( int i = 0; i < faceSize / 2; ++i )
{
Expand Down Expand Up @@ -1806,7 +1814,7 @@ QList<int> QgsTopologicalMesh::facesAroundVertex( int vertexIndex ) const
return circ.facesAround();
}

QgsMeshEditingError QgsTopologicalMesh::facesCanBeRemoved( const QList<int> facesIndexes )
QgsMeshEditingError QgsTopologicalMesh::facesCanBeRemoved( const QList<int> &facesIndexes )
{
QSet<int> removedFaces( facesIndexes.begin(), facesIndexes.end() );
QSet<int> concernedFaces = concernedFacesBy( facesIndexes );
Expand All @@ -1825,7 +1833,7 @@ QgsMeshEditingError QgsTopologicalMesh::facesCanBeRemoved( const QList<int> face
return error;
}

QgsTopologicalMesh::Changes QgsTopologicalMesh::removeFaces( const QList<int> facesIndexesToRemove )
QgsTopologicalMesh::Changes QgsTopologicalMesh::removeFaces( const QList<int> &facesIndexesToRemove )
{
Changes changes;
changes.mFaceIndexesToRemove = facesIndexesToRemove;
Expand Down
12 changes: 6 additions & 6 deletions src/core/mesh/qgstopologicalmesh.h
Expand Up @@ -213,13 +213,13 @@ class CORE_EXPORT QgsTopologicalMesh
* Returns whether faces with index in \a faceIndexes can be removed/
* The method an error object with type QgsMeshEditingError::NoError if the faces can be removed, otherwise returns the corresponding error
*/
QgsMeshEditingError facesCanBeRemoved( const QList<int> facesIndexes );
QgsMeshEditingError facesCanBeRemoved( const QList<int> &facesIndexes );

/**
* Removes faces with index in \a faceIndexes.
* The method returns a instance of the class QgsTopologicalMesh::Change that can be used to reverse or reapply the operation.
*/
Changes removeFaces( const QList<int> facesIndexes );
Changes removeFaces( const QList<int> &facesIndexes );

/**
* Returns TRUE if the edge can be flipped (only available for edge shared by two faces with 3 vertices)
Expand Down Expand Up @@ -308,11 +308,11 @@ class CORE_EXPORT QgsTopologicalMesh

/**
* Checks the topology of the \a vertices as they are contained in a face and returns indication on direction.
* If \a direction > 0 the face would be clockwise
* If the face is clockwise, \a clockwise is TRUE
*
* \since QGIS 3.28
* \since QGIS 3.30
*/
static QgsMeshEditingError checkTopologyOfVerticesAsFace( const QVector<QgsMeshVertex> &vertices, int &direction );
static QgsMeshEditingError checkTopologyOfVerticesAsFace( const QVector<QgsMeshVertex> &vertices, bool &clockwise );

/**
* Reindexes faces and vertices, after this operation, the topological
Expand Down Expand Up @@ -341,7 +341,7 @@ class CORE_EXPORT QgsTopologicalMesh
bool allowUniqueSharedVertex );

//! Returns all faces indexes that are concerned by the face with index in \a faceIndex, that is sharing a least one vertex or one edge
QSet<int> concernedFacesBy( const QList<int> faceIndexes ) const;
QSet<int> concernedFacesBy( const QList<int> &faceIndexes ) const;

//! References the vertex as a free vertex to be able to access to all free vertices
void referenceAsFreeVertex( int vertexIndex );
Expand Down

0 comments on commit e104f1b

Please sign in to comment.