30 static void ENP_centroid_step(
const QPolygonF &pX,
double &cx,
double &cy,
double &signedArea,
int i,
int i1 )
42 a = x0 * y1 - x1 * y0;
44 cx += ( x0 + x1 ) * a;
45 cy += ( y0 + y1 ) * a;
48 static void ENP_centroid(
const QPolygonF &pX,
double &cx,
double &cy )
57 double signedArea = 0.0;
61 for ( ; i < pX.size() - 1; ++i )
63 ENP_centroid_step( pX, cx, cy, signedArea, i, i + 1 );
67 ENP_centroid_step( pX, cx, cy, signedArea, i, 0 );
70 cx /= ( 6.0 * signedArea );
71 cy /= ( 6.0 * signedArea );
75 void QgsTriangularMesh::triangulate(
const QgsMeshFace &face,
int nativeIndex )
77 int vertexCount = face.size();
78 if ( vertexCount < 3 )
81 while ( vertexCount > 3 )
84 const QgsMeshFace ear = { face[vertexCount - 2], face[vertexCount - 1], face[0] };
85 mTriangularMesh.
faces.push_back( ear );
86 mTrianglesToNativeFaces.push_back( nativeIndex );
90 const QgsMeshFace triangle = { face[1], face[2], face[0] };
91 mTriangularMesh.
faces.push_back( triangle );
92 mTrianglesToNativeFaces.push_back( nativeIndex );
100 Q_ASSERT( nativeMesh );
105 mTriangularMesh.
faces.size() >= nativeMesh->
faces.size() &&
112 mTriangularMesh.
faces.clear();
113 mTrianglesToNativeFaces.clear();
114 mNativeMeshFaceCentroids.clear();
119 for (
int i = 0; i < nativeMesh->
vertices.size(); ++i )
122 if ( mCoordinateTransform.
isValid() )
129 mapVertex.
setM( vertex.
m() );
130 mTriangularMesh.
vertices[i] = mapVertex;
135 QgsDebugMsg( QStringLiteral(
"Caught CRS exception %1" ).arg( cse.
what() ) );
136 mTriangularMesh.
vertices[i] = vertex;
141 mTriangularMesh.
vertices[i] = vertex;
146 for (
int i = 0; i < nativeMesh->
faces.size(); ++i )
149 triangulate( face, i );
153 mNativeMeshFaceCentroids.resize( nativeMesh->
faces.size() );
154 for (
int i = 0; i < nativeMesh->
faces.size(); ++i )
157 QVector<QPointF> points;
158 points.reserve( face.size() );
159 for (
int j = 0; j < face.size(); ++j )
161 int index = face.at( j );
165 QPolygonF poly( points );
167 ENP_centroid( poly, cx, cy );
182 return mTriangularMesh.
faces;
187 return mNativeMeshFaceCentroids;
192 return mTrianglesToNativeFaces;
198 for (
const int faceIndex : faceIndexes )
215 QVector<QgsPoint> ring;
216 for (
int j = 0; j < face.size(); ++j )
218 int vertexId = face[j];
219 Q_ASSERT( vertexId < vertices.size() );
220 const QgsPoint &vertex = vertices[vertexId];
221 ring.append( vertex );
223 std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
235 QSet<int> nativeFaces;
236 for (
const int triangleIndex : triangleIndexes )
238 const int nativeIndex = trianglesToNativeFaces[triangleIndex];
239 nativeFaces.insert( nativeIndex );
241 return nativeFaces.toList();
CORE_EXPORT QgsGeometry toGeometry(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry.
A rectangle specified with double values.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
QPointF toQPointF() const
Returns the point as a QPointF.
int faceIndexForPoint(const QgsPointXY &point) const
Finds index of triangle at given point It uses spatial indexing.
A class to represent a 2D point.
QList< int > intersects(const QgsRectangle &rectangle) const
Returns a list of face ids with a bounding box which intersects the specified rectangle.
A geometry is the spatial representation of a feature.
QVector< QgsMeshVertex > vertices
vertices
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
void setM(double m)
Sets the point's m-value.
CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
~QgsTriangularMesh()
Dtor.
Point geometry type, with support for z-dimension and m-values.
CORE_EXPORT QList< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
QList< int > faceIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of triangles intersecting given bounding box It uses spatial indexing.
A spatial index for QgsMeshFace objects.
void update(QgsMesh *nativeMesh, QgsRenderContext *context)
Constructs triangular mesh from layer's native mesh and context.
Contains information about the context of a rendering operation.
Mesh - vertices and faces.
Line string geometry type, with support for z-dimension and m-values.
QVector< int > QgsMeshFace
List of vertex indexes.
QVector< QgsMeshFace > faces
faces
Custom exception class for Coordinate Reference System related exceptions.
bool contains(const QgsPointXY *p) const
Tests for containment of a point (uses GEOS)
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original faces.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
const QVector< QgsMeshVertex > & centroids() const
Returns centroids of the native faces in map CRS.
QgsPoint QgsMeshVertex
xyz coords of vertex