QGIS API Documentation 4.1.0-Master (01362494303)
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 Q_DECL_DEPRECATED void setTextureRotation( float rotation ) SIP_DEPRECATED;
115
120 Q_DECL_DEPRECATED float textureRotation() const SIP_DEPRECATED { return 0; }
121
128 void setAddTextureUVs( bool addTextureUVs );
129
136 bool hasTextureUVs() const { return mAddTextureCoords; }
137
144 void setAddNormals( bool addNormals );
145
152 bool hasNormals() const { return mAddNormals; }
153
160 void setAddTangents( bool addTangents );
161
168 bool hasTangents() const { return mAddTangents; }
169
176 void setBackFacesEnabled( bool addBackFaces );
177
184 bool hasBackFacesEnabled() const { return mAddBackFaces; }
185
192 void setInvertNormals( bool invertNormals );
193
200 bool hasInvertedNormals() const { return mInvertNormals; }
201
206 void setTriangulationAlgorithm( Qgis::TriangulationAlgorithm algorithm );
207
212 Qgis::TriangulationAlgorithm triangulationAlgorithm() const { return mTriangulationAlgorithm; }
213
220 Q_DECL_DEPRECATED void setOutputZUp( bool zUp ) SIP_DEPRECATED;
221
228 Q_DECL_DEPRECATED bool isOutputZUp() const SIP_DEPRECATED { return true; }
229
231 void addPolygon( const QgsPolygon &polygon, float extrusionHeight );
232
240 Q_DECL_DEPRECATED QVector<float> data() const SIP_DEPRECATED;
241
246 QByteArray indexBuffer() const;
247
252 QByteArray vertexBuffer() const;
253
255 int dataVerticesCount() const;
256
258 int stride() const { return mStride; }
259
264 int indexStride() const { return sizeof( uint32_t ); }
265
269 std::unique_ptr< QgsMultiPolygon > asMultiPolygon() const SIP_SKIP;
270
275 float zMinimum() const { return mZMin; }
276
281 float zMaximum() const { return mZMax; }
282
288 QString error() const { return mError; }
289
294 int uniqueVertexCount() const;
295
296 private:
297 struct VertexPoint
298 {
299 QVector3D position;
300 QVector3D normal;
301 QVector4D tangent;
302
303 inline bool operator==( const VertexPoint &other ) const { return position == other.position && normal == other.normal && tangent == other.tangent; }
304 };
305
306 friend uint qHash( const VertexPoint &key, size_t seed )
307 {
308 return qHashMulti( seed, key.position.x(), key.position.y(), key.position.z(), key.normal.x(), key.normal.y(), key.normal.z(), key.tangent.x(), key.tangent.y(), key.tangent.z(), key.tangent.w() );
309 }
310
311 QVector<uint32_t> mIndexBuffer;
312
313 void updateStride();
314 void setExtrusionFacesLegacy( int facade );
315 void calculateBaseTransform( const QVector3D &pNormal, QMatrix4x4 *base ) const;
316 QVector3D applyTransformWithExtrusion( const QVector3D point, float extrusionHeight, QMatrix4x4 *transformMatrix, const QgsPoint *originOffset );
317 void addVertex(
318 const QVector3D &point,
319 const QVector3D &normal,
320 const QVector4D &tangent,
321 float extrusionHeight,
322 QMatrix4x4 *transformMatrix,
323 const QgsPoint *originOffset,
324 QHash<VertexPoint, unsigned int> *vertexBuffer,
325 const size_t &vertexBufferOffset,
326 bool isFloor = false
327 );
328 void addVertex( const QVector3D &point, const QVector3D &normal, const QVector4D &tangent, float extrusionHeight, QMatrix4x4 *transformMatrix, const QgsPoint *originOffset, bool isFloor = false );
329 void makeWalls( const QgsLineString &ring, bool ccw, float extrusionHeight );
330 void addExtrusionWallQuad( const QVector3D &pt1, const QVector3D &pt2, float height, float u1, float u2 );
331 void ringToEarcutPoints( const QgsLineString *ring, std::vector<std::array<double, 2>> &polyline, QHash<std::array<double, 2> *, float> *zHash );
332 std::vector<QVector3D> generateConstrainedDelaunayTriangles( const QgsPolygon *polygonNew );
333 std::vector<QVector3D> generateEarcutTriangles( const QgsPolygon *polygonNew );
334
335 QgsVector3D mOrigin = QgsVector3D( 0, 0, 0 );
336 bool mAddNormals = false;
337 bool mAddTangents = false;
338 bool mInvertNormals = false;
339 bool mAddBackFaces = false;
340 bool mAddTextureCoords = false;
341 QVector<float> mData;
342 int mStride = 3 * sizeof( float );
343 bool mInputZValueIgnored = false;
346 float mScale = 1.0f;
347 QString mError;
348
349 float mZMin = std::numeric_limits<float>::max();
350 float mZMax = -std::numeric_limits<float>::max();
351};
352
353
354#endif // QGSTESSELLATOR_H
TriangulationAlgorithm
Triangulation algorithms.
Definition qgis.h:6678
QFlags< ExtrusionFace > ExtrusionFaces
Tessellator extrusion face types.
Definition qgis.h:6670
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.
bool hasTextureUVs() const
Returns true if texture UV coordinates are being added to the output data.
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.
Q_DECL_DEPRECATED bool isOutputZUp() const
Returns whether the "up" direction should be the Z axis on output (true), otherwise the "up" directio...
int indexStride() const
Returns size of one index entry in bytes.
bool hasBackFacesEnabled() const
Returns true if back faces are being added to the output data.
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.
QString error() const
Returns a descriptive error string if the tessellation failed.
Qgis::TriangulationAlgorithm triangulationAlgorithm() const
Returns the algorithm used for triangulation.
bool hasTangents() const
Returns true if tangents are being added to the output data.
friend uint qHash(const VertexPoint &key, size_t seed)
bool hasNormals() const
Returns true if normals are being added to the output data.
bool hasInvertedNormals() const
Returns true if normals are inverted.
float zMaximum() const
Returns maximal Z value of the data (in world coordinates).
Q_DECL_DEPRECATED float textureRotation() const
Returns the rotation of texture UV coordinates (in degrees).
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
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)