QGIS API Documentation 4.1.0-Master (31622b25bb0)
Loading...
Searching...
No Matches
qgstriangulatedsurface.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstriangulatedsurface.h
3 -------------------
4 begin : August 2024
5 copyright : (C) 2024 by Jean Felder
6 email : jean dot felder at oslandia dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSTRIANGULATEDSURFACE_H
19#define QGSTRIANGULATEDSURFACE_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
24
25#include <QString>
26
27using namespace Qt::StringLiterals;
28
29class QgsTriangle;
30
31
42{
43 public:
47
48#ifndef SIP_RUN
49 private:
50 bool fuzzyHelper( const QgsAbstractGeometry &other, double epsilon, bool useDistance ) const
51 {
52 const QgsTriangulatedSurface *otherTriangulatedSurface = qgsgeometry_cast< const QgsTriangulatedSurface * >( &other );
53 if ( !otherTriangulatedSurface )
54 return false;
55
56 //run cheap checks first
57 if ( mWkbType != otherTriangulatedSurface->mWkbType )
58 return false;
59
60 if ( mPatches.count() != otherTriangulatedSurface->mPatches.count() )
61 return false;
62
63 for ( int i = 0; i < mPatches.count(); ++i )
64 {
65 if ( ( !mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) ) || ( mPatches.at( i ) && !otherTriangulatedSurface->mPatches.at( i ) ) )
66 return false;
67
68 if ( useDistance )
69 {
70 if ( mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) && !( *mPatches.at( i ) ).fuzzyDistanceEqual( *otherTriangulatedSurface->mPatches.at( i ), epsilon ) )
71 return false;
72 }
73 else
74 {
75 if ( mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) && !( *mPatches.at( i ) ).fuzzyEqual( *otherTriangulatedSurface->mPatches.at( i ), epsilon ) )
76 return false;
77 }
78 }
79
80 return true;
81 }
82#endif
83
84 public:
85 // clang-format off
86 bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
87 // clang-format on
88 {
89 return fuzzyHelper( other, epsilon, false );
90 }
91 bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
92 {
93 return fuzzyHelper( other, epsilon, true );
94 }
95
96 bool operator==( const QgsAbstractGeometry &other ) const override
97 {
98 return fuzzyEqual( other, 1e-8 );
99 }
100
101 bool operator!=( const QgsAbstractGeometry &other ) const override
102 {
103 return !operator==( other );
104 }
105
106 ~QgsTriangulatedSurface() override;
107
108 QString geometryType() const override SIP_HOLDGIL;
109 QgsTriangulatedSurface *clone() const override SIP_FACTORY;
110 void clear() override;
111
112 bool fromWkb( QgsConstWkbPtr &wkb ) override;
113 bool fromWkt( const QString &wkt ) override;
114
115 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
116 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
117 QString asKml( int precision = 17 ) const override;
118 void normalize() override SIP_HOLDGIL;
119
120 //surface interface
121 QgsTriangulatedSurface *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
122
123 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
124 bool deleteVertex( QgsVertexId position ) override;
125 bool deleteVertices( const QSet<QgsVertexId> &positions ) override;
126
130 void setTriangles( const QVector<QgsTriangle *> &triangles SIP_TRANSFER );
131
135 void addPatch( QgsPolygon *patch SIP_TRANSFER ) override;
136
140 void addTriangle( QgsTriangle *triangle SIP_TRANSFER );
141
142#ifndef SIP_RUN
143
147 QgsTriangle *triangleN( int index );
148#else
149// clang-format off
150
156 SIP_PYOBJECT triangleN( int index ) SIP_TYPEHINT( QgsPolygon );
157 % MethodCode
158 if ( a0 < 0 || a0 >= sipCpp->numPatches() )
159 {
160 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
161 sipIsErr = 1;
162 }
163 else
164 {
165 return sipConvertFromType( sipCpp->triangleN( a0 ), sipType_QgsTriangle, NULL );
166 }
167 % End
168// clang-format on
169#endif
170
171#ifndef SIP_RUN
172
178 const QgsTriangle *triangleN( int index ) const;
179#endif
180
181#ifndef SIP_RUN
182
191 inline static const QgsTriangulatedSurface *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
192 {
193 if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == Qgis::WkbType::TIN )
194 return static_cast<const QgsTriangulatedSurface *>( geom );
195
196 return nullptr;
197 }
198
207 inline static QgsTriangulatedSurface *cast( QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
208 {
209 if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == Qgis::WkbType::TIN )
210 return static_cast<QgsTriangulatedSurface *>( geom );
211
212 return nullptr;
213 }
214#endif
215
217
218#ifdef SIP_RUN
219// clang-format off
220 SIP_PYOBJECT __repr__();
221 % MethodCode
222 QString wkt = sipCpp->asWkt();
223 if ( wkt.length() > 1000 )
224 wkt = wkt.left( 1000 ) + u"..."_s;
225 QString str = u"<QgsTriangulatedSurface: %1>"_s.arg( wkt );
226 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
227 % End
228// clang-format on
229#endif
230
231 protected:
232
233 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
234};
235
236// clazy:excludeall=qstring-allocations
237
238#endif // QGSTRIANGULATEDSURFACE_H
@ TIN
TIN.
Definition qgis.h:310
Abstract base class for all geometries.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
QgsAbstractGeometry()=default
A const WKB pointer.
Definition qgswkbptr.h:211
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
Polygon geometry type.
Definition qgspolygon.h:37
QVector< QgsPolygon * > mPatches
QString geometryType() const override
Returns a unique string representing the geometry type.
int compareToSameClass(const QgsAbstractGeometry *other) const override
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
QgsPolyhedralSurface * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy comparison between this geometry and other using an epsilon.
bool operator==(const QgsAbstractGeometry &other) const override
QgsPolyhedralSurface & operator=(const QgsPolyhedralSurface &p)
Triangle geometry type.
Definition qgstriangle.h:33
Triangulated surface geometry type.
bool operator!=(const QgsAbstractGeometry &other) const override
static QgsTriangulatedSurface * cast(QgsAbstractGeometry *geom)
Cast the geom to a QgsTriangulatedSurface.
bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy comparison between this geometry and other using an epsilon.
bool fuzzyDistanceEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy distance comparison between this geometry and other using an epsilon.
static const QgsTriangulatedSurface * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsTriangulatedSurface.
bool operator==(const QgsAbstractGeometry &other) const override
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:237
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_HOLDGIL
Definition qgis_sip.h:178
#define SIP_FACTORY
Definition qgis_sip.h:83
T qgsgeometry_cast(QgsAbstractGeometry *geom)
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:35