33 QgsMeshFeatureIterator::QgsMeshFeatureIterator(
QgsMesh *mesh )
38 QgsMeshFeatureIterator::~QgsMeshFeatureIterator() =
default;
40 bool QgsMeshFeatureIterator::rewind()
45 bool QgsMeshFeatureIterator::close()
51 bool QgsMeshFeatureIterator::fetchFeature(
QgsFeature &f )
53 if ( !mMesh || mMesh->faces.size() <= it )
67 static void ENP_centroid_step(
const QPolygonF &pX,
double &cx,
double &cy,
double &signedArea,
int i,
int i1 )
79 a = x0 * y1 - x1 * y0;
81 cx += ( x0 + x1 ) * a;
82 cy += ( y0 + y1 ) * a;
85 static void ENP_centroid(
const QPolygonF &pX,
double &cx,
double &cy )
94 double signedArea = 0.0;
98 for ( ; i < pX.size() - 1; ++i )
100 ENP_centroid_step( pX, cx, cy, signedArea, i, i + 1 );
104 ENP_centroid_step( pX, cx, cy, signedArea, i, 0 );
107 cx /= ( 6.0 * signedArea );
108 cy /= ( 6.0 * signedArea );
113 Q_ASSERT( nativeMesh );
118 mTriangularMesh.
faces.size() >= nativeMesh->
faces.size() &&
125 mTriangularMesh.
faces.clear();
126 mTrianglesToNativeFaces.clear();
127 mNativeMeshFaceCentroids.clear();
132 for (
int i = 0; i < nativeMesh->
vertices.size(); ++i )
135 if ( mCoordinateTransform.
isValid() )
141 mapVertex.
setZ( vertex.
z() );
142 mapVertex.
setM( vertex.
m() );
143 mTriangularMesh.
vertices[i] = mapVertex;
148 QgsDebugMsg( QStringLiteral(
"Caught CRS exception %1" ).arg( cse.
what() ) );
149 mTriangularMesh.
vertices[i] = vertex;
154 mTriangularMesh.
vertices[i] = vertex;
159 for (
int i = 0; i < nativeMesh->
faces.size(); ++i )
162 if ( face.size() == 3 )
165 mTriangularMesh.
faces.push_back( face );
166 mTrianglesToNativeFaces.push_back( i );
168 else if ( face.size() == 4 )
172 face1.push_back( face[0] );
173 face1.push_back( face[1] );
174 face1.push_back( face[2] );
176 mTriangularMesh.
faces.push_back( face1 );
177 mTrianglesToNativeFaces.push_back( i );
180 face2.push_back( face[0] );
181 face2.push_back( face[2] );
182 face2.push_back( face[3] );
184 mTriangularMesh.
faces.push_back( face2 );
185 mTrianglesToNativeFaces.push_back( i );
190 mNativeMeshFaceCentroids.resize( nativeMesh->
faces.size() );
191 for (
int i = 0; i < nativeMesh->
faces.size(); ++i )
194 QVector<QPointF> points;
195 points.reserve( face.size() );
196 for (
int j = 0; j < face.size(); ++j )
198 int index = face.at( j );
202 QPolygonF poly( points );
204 ENP_centroid( poly, cx, cy );
209 mSpatialIndex =
QgsSpatialIndex(
new QgsMeshFeatureIterator( &mTriangularMesh ) );
219 return mTriangularMesh.
faces;
224 return mNativeMeshFaceCentroids;
229 return mTrianglesToNativeFaces;
237 int faceIndex =
static_cast<int>( fid );
248 const QList<QgsFeatureId> faceIndexes = mSpatialIndex.
intersects( rectangle );
252 int faceIndex =
static_cast<int>( fid );
253 indexes.append( faceIndex );
260 QVector<QgsPoint> ring;
261 for (
int j = 0; j < face.size(); ++j )
263 int vertexId = face[j];
264 Q_ASSERT( vertexId < vertices.size() );
265 const QgsPoint &vertex = vertices[vertexId];
266 ring.append( vertex );
268 std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
275 QSet<int> nativeFaces;
276 for (
const int triangleIndex : triangleIndexes )
278 const int nativeIndex = trianglesToNativeFaces[triangleIndex];
279 nativeFaces.insert( nativeIndex );
281 return nativeFaces.toList();
int faceIndexForPoint(const QgsPointXY &point) const
Finds index of triangle at given point It uses spatial indexing.
QgsGeometry toGeometry(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry.
A rectangle specified with double values.
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
void setZ(double z)
Sets the point's z-coordinate.
A class to represent a 2D point.
A geometry is the spatial representation of a feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool contains(const QgsPointXY *p) const
Tests for containment of a point (uses GEOS)
QVector< QgsMeshVertex > vertices
vertices
void setM(double m)
Sets the point's m-value.
Internal feature iterator to be implemented within data providers.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setId(QgsFeatureId id)
Sets the feature ID for this feature.
Point geometry type, with support for z-dimension and m-values.
QList< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
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.
A spatial index for QgsFeature objects.
const QVector< QgsMeshVertex > & centroids() const
Returns centroids of the native faces in map CRS.
Line string geometry type, with support for z-dimension and m-values.
QVector< int > QgsMeshFace
List of vertex indexes.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QVector< QgsMeshFace > faces
faces
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original faces.
Custom exception class for Coordinate Reference System related exceptions.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
QList< int > faceIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of triangles intersecting given bounding box It uses spatial indexing.
QgsPoint QgsMeshVertex
xyz coords of vertex
QPointF toQPointF() const
Returns the point as a QPointF.