22 static void ENP_centroid_step(
const QPolygonF &pX,
double &cx,
double &cy,
double &signedArea,
int i,
int i1 )
34 a = x0 * y1 - x1 * y0;
36 cx += ( x0 + x1 ) * a;
37 cy += ( y0 + y1 ) * a;
40 static void ENP_centroid(
const QPolygonF &pX,
double &cx,
double &cy )
49 double signedArea = 0.0;
53 for ( ; i < pX.size() - 1; ++i )
55 ENP_centroid_step( pX, cx, cy, signedArea, i, i + 1 );
59 ENP_centroid_step( pX, cx, cy, signedArea, i, 0 );
62 cx /= ( 6.0 * signedArea );
63 cy /= ( 6.0 * signedArea );
69 Q_ASSERT( nativeMesh );
73 mTriangularMesh.
faces.clear();
74 mTrianglesToNativeFaces.clear();
75 mNativeMeshFaceCentroids.clear();
80 for (
int i = 0; i < nativeMesh->
vertices.size(); ++i )
87 mapVertex.
setZ( vertex.
z() );
88 mapVertex.
setM( vertex.
m() );
89 mTriangularMesh.
vertices[i] = mapVertex;
93 mTriangularMesh.
vertices[i] = vertex;
98 for (
int i = 0; i < nativeMesh->
faces.size(); ++i )
101 if ( face.size() == 3 )
104 mTriangularMesh.
faces.push_back( face );
105 mTrianglesToNativeFaces.push_back( i );
107 else if ( face.size() == 4 )
111 face1.push_back( face[0] );
112 face1.push_back( face[1] );
113 face1.push_back( face[2] );
115 mTriangularMesh.
faces.push_back( face1 );
116 mTrianglesToNativeFaces.push_back( i );
119 face2.push_back( face[0] );
120 face2.push_back( face[2] );
121 face2.push_back( face[3] );
123 mTriangularMesh.
faces.push_back( face2 );
124 mTrianglesToNativeFaces.push_back( i );
129 mNativeMeshFaceCentroids.resize( nativeMesh->
faces.size() );
130 for (
int i = 0; i < nativeMesh->
faces.size(); ++i )
133 QVector<QPointF> points;
134 points.reserve( face.size() );
135 for (
int j = 0; j < face.size(); ++j )
137 int index = face.at( j );
141 QPolygonF poly( points );
143 ENP_centroid( poly, cx, cy );
155 return mTriangularMesh.
faces;
160 return mNativeMeshFaceCentroids;
165 return mTrianglesToNativeFaces;
QPointF toQPointF() const
Returns the point as a QPointF.
void setZ(double z)
Sets the point's z-coordinate.
A class to represent a 2D point.
QVector< QgsMeshVertex > vertices
vertices
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
void setM(double m)
Sets the point's m-value.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context, or an invalid transform is no coordinate tr...
Point geometry type, with support for z-dimension and m-values.
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.
QVector< int > QgsMeshFace
List of vertex indexes.
QVector< QgsMeshFace > faces
faces
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original faces.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map CRS.
const QVector< QgsMeshVertex > & centroids() const
Returns centroids of the native faces in map CRS.
QgsPoint QgsMeshVertex
xyz coords of vertex