QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgstessellator.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstessellator.h
3 --------------------------------------
4 Date : July 2017
5 Copyright : (C) 2017 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSTESSELLATOR_H
17#define QGSTESSELLATOR_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsrectangle.h"
22
23class QgsPolygon;
24class QgsMultiPolygon;
25class QgsLineString;
26
27#include <QVector>
28#include <memory>
29
40class CORE_EXPORT QgsTessellator
41{
42 public:
44
49 Q_DECL_DEPRECATED QgsTessellator(
50 double originX, double originY, bool addNormals, bool invertNormals = false, bool addBackFaces = false, bool noZ = false, bool addTextureCoords = false, int facade = 3, float textureRotation = 0.0f
52
63 Q_DECL_DEPRECATED QgsTessellator(
64 const QgsRectangle &bounds, bool addNormals, bool invertNormals = false, bool addBackFaces = false, bool noZ = false, bool addTextureCoords = false, int facade = 3, float textureRotation = 0.0f
66
71 void setOrigin( const QgsVector3D &origin );
72
77 QgsVector3D origin() const { return mOrigin; }
78
83 void setBounds( const QgsRectangle &bounds );
84
90 void setInputZValueIgnored( bool ignore );
91
96 bool isZValueIgnored() const { return mInputZValueIgnored; }
97
102 void setExtrusionFaces( Qgis::ExtrusionFaces faces );
103
108 Qgis::ExtrusionFaces extrusionFaces() const { return mExtrusionFaces; }
109
114 void setTextureRotation( float rotation );
115
120 float textureRotation() const { return mTextureRotation; }
121
126 void setAddTextureUVs( bool addTextureUVs );
127
132 bool hasTextureUVs() const { return mAddTextureCoords; }
133
138 void setAddNormals( bool addNormals );
139
144 bool hasNormals() const { return mAddNormals; }
145
150 void setBackFacesEnabled( bool addBackFaces );
151
156 bool hasBackFacesEnabled() const { return mAddBackFaces; }
157
162 void setInvertNormals( bool invertNormals );
163
168 bool hasInvertedNormals() const { return mInvertNormals; }
169
174 void setTriangulationAlgorithm( Qgis::TriangulationAlgorithm algorithm );
175
180 Qgis::TriangulationAlgorithm triangulationAlgorithm() const { return mTriangulationAlgorithm; }
181
188 void setOutputZUp( bool zUp ) { mOutputZUp = zUp; }
189
196 bool isOutputZUp() const { return mOutputZUp; }
197
199 void addPolygon( const QgsPolygon &polygon, float extrusionHeight );
200
208 Q_DECL_DEPRECATED QVector<float> data() const SIP_DEPRECATED;
209
214 QByteArray indexBuffer() const;
215
220 QByteArray vertexBuffer() const;
221
223 int dataVerticesCount() const;
224
226 int stride() const { return mStride; }
227
232 int indexStride() const { return sizeof( uint32_t ); }
233
237 std::unique_ptr< QgsMultiPolygon > asMultiPolygon() const SIP_SKIP;
238
243 float zMinimum() const { return mZMin; }
244
249 float zMaximum() const { return mZMax; }
250
256 QString error() const { return mError; }
257
262 int uniqueVertexCount() const;
263
264 private:
265 struct VertexPoint
266 {
267 QVector3D position;
268 QVector3D normal;
269
270 inline bool operator==( const VertexPoint &other ) const { return position == other.position && normal == other.normal; }
271 };
272
273 friend uint qHash( const VertexPoint &key )
274 {
275 return qHash( key.position.x() ) ^ qHash( key.position.y() ) ^ qHash( key.position.z() ) ^ qHash( key.normal.x() ) ^ qHash( key.normal.y() ) ^ qHash( key.normal.z() );
276 }
277
278 QVector<uint32_t> mIndexBuffer;
279
280 void updateStride();
281 void setExtrusionFacesLegacy( int facade );
282 void calculateBaseTransform( const QVector3D &pNormal, QMatrix4x4 *base ) const;
283 QVector3D applyTransformWithExtrusion( const QVector3D point, float extrusionHeight, QMatrix4x4 *transformMatrix, const QgsPoint *originOffset );
284 void addVertex(
285 const QVector3D &point, const QVector3D &normal, float extrusionHeight, QMatrix4x4 *transformMatrix, const QgsPoint *originOffset, QHash<VertexPoint, unsigned int> *vertexBuffer, const size_t &vertexBufferOffset
286 );
287 void addVertex( const QVector3D &point, const QVector3D &normal, float extrusionHeight, QMatrix4x4 *transformMatrix, const QgsPoint *originOffset );
288 void makeWalls( const QgsLineString &ring, bool ccw, float extrusionHeight );
289 void addExtrusionWallQuad( const QVector3D &pt1, const QVector3D &pt2, float height );
290 void ringToEarcutPoints( const QgsLineString *ring, std::vector<std::array<double, 2>> &polyline, QHash<std::array<double, 2> *, float> *zHash );
291 std::vector<QVector3D> generateConstrainedDelaunayTriangles( const QgsPolygon *polygonNew );
292 std::vector<QVector3D> generateEarcutTriangles( const QgsPolygon *polygonNew );
293
294 QgsVector3D mOrigin = QgsVector3D( 0, 0, 0 );
295 bool mAddNormals = false;
296 bool mInvertNormals = false;
297 bool mAddBackFaces = false;
298 bool mAddTextureCoords = false;
299 bool mOutputZUp = false;
300 QVector<float> mData;
301 int mStride = 3 * sizeof( float );
302 bool mInputZValueIgnored = false;
305 float mTextureRotation = 0.0f;
306 float mScale = 1.0f;
307 QString mError;
308
309 float mZMin = std::numeric_limits<float>::max();
310 float mZMax = -std::numeric_limits<float>::max();
311};
312
313
314#endif // QGSTESSELLATOR_H
TriangulationAlgorithm
Triangulation algorithms.
Definition qgis.h:6534
QFlags< ExtrusionFace > ExtrusionFaces
Tessellator extrusion face types.
Definition qgis.h:6526
Line string geometry type, with support for z-dimension and m-values.
Multi polygon geometry collection.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
Polygon geometry type.
Definition qgspolygon.h:37
A rectangle specified with double values.
float textureRotation() const
Returns the rotation of texture UV coordinates (in degrees).
bool hasTextureUVs() const
Returns whether texture UV coordinates are being added to the output data (true) or not (false).
void setOrigin(const QgsVector3D &origin)
Sets the origin point of the map.
bool isZValueIgnored() const
Returns whether Z values from the input geometries are ignored (true) or not (false).
int stride() const
Returns size of one vertex entry in bytes.
int indexStride() const
Returns size of one index entry in bytes.
bool hasBackFacesEnabled() const
Returns whether back faces are being added to the output data (true) or not (false).
float zMinimum() const
Returns minimal Z value of the data (in world coordinates).
Qgis::ExtrusionFaces extrusionFaces() const
Returns which faces are generated during extrusion.
QgsVector3D origin() const
Returns the origin point of the map.
friend uint qHash(const VertexPoint &key)
QString error() const
Returns a descriptive error string if the tessellation failed.
Qgis::TriangulationAlgorithm triangulationAlgorithm() const
Returns the algorithm used for triangulation.
void setOutputZUp(bool zUp)
Sets whether the "up" direction should be the Z axis on output (true), otherwise the "up" direction w...
bool isOutputZUp() const
Returns whether the "up" direction should be the Z axis on output (true), otherwise the "up" directio...
bool hasNormals() const
Returns whether normals are being added to the output data (true) or not (false).
bool hasInvertedNormals() const
Returns whether normals are inverted (true) or not (false).
float zMaximum() const
Returns maximal Z value of the data (in world coordinates).
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
uint qHash(const QVariant &variant)
Hash for QVariant.
Definition qgis.cpp:611
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)