Skip to content

Commit

Permalink
fix force by lines with different CRS
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Sep 21, 2021
1 parent c2243a7 commit 11d3881
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
36 changes: 23 additions & 13 deletions src/core/mesh/qgsmeshforcebypolylines.cpp
Expand Up @@ -370,7 +370,7 @@ bool QgsMeshEditForceByLine::buildForcedElements()
QgsPoint intersectionPoint( 0, 0, 0 );
int edgePosition = -1;

bool result = searchIntersectionEdgeFromSnappedVertex_v2(
bool result = searchIntersectionEdgeFromSnappedVertex(
intersectionFaceIndex,
previousSnappedVertex,
mCurrentSnappedVertex,
Expand Down Expand Up @@ -439,10 +439,12 @@ bool QgsMeshEditForceByLine::buildForcedElements()
currentAddedVertex = startingVertexIndex + mVerticesToAdd.count();
mNewVerticesIndexesOnLine.append( mVerticesToAdd.count() );
if ( mInterpolateZValueOnMesh )
interPolateZValue( intersectionPoint, mesh->vertex( iv1 ), mesh->vertex( iv2 ) );
interPolateZValue( intersectionPoint,
triangularMesh->vertices().at( iv1 ),
triangularMesh->vertices().at( iv2 ) );
else
interPolateZValue( intersectionPoint, mPoint1, mPoint2 );
mVerticesToAdd.append( intersectionPoint );
mVerticesToAdd.append( triangularMesh->triangularToNativeCoordinates( intersectionPoint ) );
}

if ( nextCutFace != -1 )
Expand All @@ -458,10 +460,12 @@ bool QgsMeshEditForceByLine::buildForcedElements()
{
currentAddedVertex = startingVertexIndex + mVerticesToAdd.count();
if ( mInterpolateZValueOnMesh )
interPolateZValue( intersectionPoint, mesh->vertex( iv1 ), mesh->vertex( iv2 ) );
interPolateZValue( intersectionPoint,
triangularMesh->vertices().at( iv1 ),
triangularMesh->vertices().at( iv2 ) );
else
interPolateZValue( intersectionPoint, mPoint1, mPoint2 );
mVerticesToAdd.append( intersectionPoint );
mVerticesToAdd.append( triangularMesh->triangularToNativeCoordinates( intersectionPoint ) );
}
else
mNewVerticesIndexesOnLine.removeLast();
Expand Down Expand Up @@ -540,10 +544,12 @@ bool QgsMeshEditForceByLine::buildForcedElements()
currentAddedVertex = startingVertexIndex + mVerticesToAdd.count();
mNewVerticesIndexesOnLine.append( mVerticesToAdd.count() );
if ( mInterpolateZValueOnMesh )
interPolateZValue( intersection, mesh->vertex( iv1 ), mesh->vertex( iv2 ) );
interPolateZValue( intersection,
triangularMesh->vertices().at( iv1 ),
triangularMesh->vertices().at( iv2 ) );
else
interPolateZValue( intersection, mPoint1, mPoint2 );
mVerticesToAdd.append( intersection );
mVerticesToAdd.append( triangularMesh->triangularToNativeCoordinates( intersection ) );
}
}

Expand Down Expand Up @@ -591,10 +597,12 @@ bool QgsMeshEditForceByLine::buildForcedElements()
{
currentAddedVertex = startingVertexIndex + mVerticesToAdd.count();
if ( mInterpolateZValueOnMesh )
interPolateZValue( intersection, mesh->vertex( iv1 ), mesh->vertex( iv2 ) );
interPolateZValue( intersection,
triangularMesh->vertices().at( iv1 ),
triangularMesh->vertices().at( iv2 ) );
else
interPolateZValue( intersection, mPoint1, mPoint2 );
mVerticesToAdd.append( intersection );
mVerticesToAdd.append( triangularMesh->triangularToNativeCoordinates( intersection ) );
}
else
mNewVerticesIndexesOnLine.removeLast();
Expand Down Expand Up @@ -705,11 +713,13 @@ bool QgsMeshEditForceByLine::buildForcedElements()
currentEdge = {mHoleOnLeft.last(), mHoleOnRight.last()};

if ( mInterpolateZValueOnMesh )
interPolateZValue( closestIntersectionPoint, mesh->vertex( mHoleOnLeft.last() ), mesh->vertex( mHoleOnRight.last() ) );
interPolateZValue( closestIntersectionPoint,
triangularMesh->vertices().at( mHoleOnLeft.last() ),
triangularMesh->vertices().at( mHoleOnRight.last() ) );
else
interPolateZValue( closestIntersectionPoint, mPoint1, mPoint2 );

mVerticesToAdd.append( closestIntersectionPoint );
mVerticesToAdd.append( triangularMesh->triangularToNativeCoordinates( closestIntersectionPoint ) );

}
}
Expand Down Expand Up @@ -748,7 +758,7 @@ bool QgsMeshEditForceByLine::buildForcedElements()
}


bool QgsMeshEditForceByLine::searchIntersectionEdgeFromSnappedVertex_v2
bool QgsMeshEditForceByLine::searchIntersectionEdgeFromSnappedVertex
( int &intersectionFaceIndex,
int &previousSnappedVertex,
int &currentSnappedVertexIndex,
Expand All @@ -762,7 +772,7 @@ bool QgsMeshEditForceByLine::searchIntersectionEdgeFromSnappedVertex_v2
while ( true )
{
treatedVertices.insert( currentSnappedVertexIndex );
QList<int> facesAround = mEditor->topologicalMesh().facesAroundVertex( currentSnappedVertexIndex );
const QList<int> facesAround = mEditor->topologicalMesh().facesAroundVertex( currentSnappedVertexIndex );

bool foundSomething = false;
for ( const int faceIndex : std::as_const( facesAround ) )
Expand Down
2 changes: 1 addition & 1 deletion src/core/mesh/qgsmeshforcebypolylines.h
Expand Up @@ -103,7 +103,7 @@ class CORE_EXPORT QgsMeshEditForceByLine : public QgsMeshAdvancedEditing
QgsPoint &intersectionPoint,
bool outAllowed );

bool searchIntersectionEdgeFromSnappedVertex_v2(
bool searchIntersectionEdgeFromSnappedVertex(
int &intersectionFaceIndex,
int &previousSnappedVertex,
int &currentSnappedVertexIndex,
Expand Down
9 changes: 5 additions & 4 deletions src/core/mesh/qgstopologicalmesh.cpp
Expand Up @@ -102,8 +102,7 @@ int QgsMeshVertexCirculator::turnCounterClockwise() const
else
{
int currentPos = positionInCurrentFace();
if ( currentPos == -1 )
return -1;
Q_ASSERT( currentPos != -1 );

const QgsMeshFace &currentFace = mFaces.at( mCurrentFace );
int faceSize = currentFace.size();
Expand All @@ -121,8 +120,7 @@ int QgsMeshVertexCirculator::turnClockwise() const
else
{
int currentPos = positionInCurrentFace();
if ( currentPos == -1 )
return -1;
Q_ASSERT( currentPos != -1 );

const QgsMeshFace &currentFace = mFaces.at( mCurrentFace );
int faceSize = currentFace.size();
Expand Down Expand Up @@ -571,6 +569,9 @@ QgsMeshEditingError QgsTopologicalMesh::checkConsistency() const
{
if ( !mMesh->face( mVertexToFace.at( vertexIndex ) ).contains( vertexIndex ) )
return QgsMeshEditingError( Qgis::MeshEditingErrorType::InvalidVertex, vertexIndex );

if ( facesAroundVertex( vertexIndex ).count() == 0 )
return QgsMeshEditingError( Qgis::MeshEditingErrorType::InvalidVertex, vertexIndex );
}
}

Expand Down

0 comments on commit 11d3881

Please sign in to comment.