QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
geometry
qgsnurbsutils.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsnurbsutils.cpp
3
-----------------
4
begin : December 2025
5
copyright : (C) 2025 by Loïc Bartoletti
6
email : loic dot bartoletti 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
#include "
qgsnurbsutils.h
"
19
20
#include "
qgscompoundcurve.h
"
21
#include "
qgscurvepolygon.h
"
22
#include "
qgsgeometrycollection.h
"
23
#include "
qgsnurbscurve.h
"
24
#include "
qgsvertexid.h
"
25
26
bool
QgsNurbsUtils::containsNurbsCurve
(
const
QgsAbstractGeometry
*geom )
27
{
28
if
( !geom )
29
return
false
;
30
31
if
(
qgsgeometry_cast<const QgsNurbsCurve *>
( geom ) )
32
return
true
;
33
34
if
(
const
QgsGeometryCollection
*gc =
qgsgeometry_cast<const QgsGeometryCollection *>
( geom ) )
35
{
36
for
(
int
i = 0; i < gc->numGeometries(); ++i )
37
{
38
if
(
containsNurbsCurve
( gc->geometryN( i ) ) )
39
return
true
;
40
}
41
}
42
43
if
(
const
QgsCurvePolygon
*cp =
qgsgeometry_cast<const QgsCurvePolygon *>
( geom ) )
44
{
45
if
(
containsNurbsCurve
( cp->exteriorRing() ) )
46
return
true
;
47
for
(
int
i = 0; i < cp->numInteriorRings(); ++i )
48
{
49
if
(
containsNurbsCurve
( cp->interiorRing( i ) ) )
50
return
true
;
51
}
52
}
53
54
if
(
const
QgsCompoundCurve
*cc =
qgsgeometry_cast<const QgsCompoundCurve *>
( geom ) )
55
{
56
for
(
int
i = 0; i < cc->nCurves(); ++i )
57
{
58
if
(
containsNurbsCurve
( cc->curveAt( i ) ) )
59
return
true
;
60
}
61
}
62
63
return
false
;
64
}
65
66
const
QgsNurbsCurve
*
QgsNurbsUtils::extractNurbsCurve
(
const
QgsAbstractGeometry
*geom )
67
{
68
if
( !geom )
69
return
nullptr
;
70
71
if
(
const
QgsNurbsCurve
*nurbs =
qgsgeometry_cast<const QgsNurbsCurve *>
( geom ) )
72
return
nurbs;
73
74
if
(
const
QgsGeometryCollection
*gc =
qgsgeometry_cast<const QgsGeometryCollection *>
( geom ) )
75
{
76
for
(
int
i = 0; i < gc->numGeometries(); ++i )
77
{
78
const
QgsNurbsCurve
*nurbs =
extractNurbsCurve
( gc->geometryN( i ) );
79
if
( nurbs )
80
return
nurbs;
81
}
82
}
83
84
if
(
const
QgsCurvePolygon
*cp =
qgsgeometry_cast<const QgsCurvePolygon *>
( geom ) )
85
{
86
const
QgsNurbsCurve
*nurbs =
extractNurbsCurve
( cp->exteriorRing() );
87
if
( nurbs )
88
return
nurbs;
89
for
(
int
i = 0; i < cp->numInteriorRings(); ++i )
90
{
91
nurbs =
extractNurbsCurve
( cp->interiorRing( i ) );
92
if
( nurbs )
93
return
nurbs;
94
}
95
}
96
97
if
(
const
QgsCompoundCurve
*cc =
qgsgeometry_cast<const QgsCompoundCurve *>
( geom ) )
98
{
99
for
(
int
i = 0; i < cc->nCurves(); ++i )
100
{
101
const
QgsNurbsCurve
*nurbs =
extractNurbsCurve
( cc->curveAt( i ) );
102
if
( nurbs )
103
return
nurbs;
104
}
105
}
106
107
return
nullptr
;
108
}
109
110
const
QgsNurbsCurve
*
QgsNurbsUtils::findNurbsCurveForVertex
(
const
QgsAbstractGeometry
*geom,
const
QgsVertexId
&vid,
int
&localIndex )
111
{
112
if
( !geom )
113
return
nullptr
;
114
115
// Direct NURBS curve
116
if
(
const
QgsNurbsCurve
*nurbs =
qgsgeometry_cast<const QgsNurbsCurve *>
( geom ) )
117
{
118
localIndex = vid.
vertex
;
119
return
nurbs;
120
}
121
122
// Compound curve - find the curve containing this vertex
123
if
(
const
QgsCompoundCurve
*compound =
qgsgeometry_cast<const QgsCompoundCurve *>
( geom ) )
124
{
125
int
vertexOffset = 0;
126
for
(
int
i = 0; i < compound->nCurves(); ++i )
127
{
128
const
QgsCurve
*curve = compound->curveAt( i );
129
const
int
curveVertexCount = curve->
numPoints
();
130
131
// Check if vertex is in this curve (accounting for shared endpoints)
132
const
int
adjustedCount = ( i == compound->nCurves() - 1 ) ? curveVertexCount : curveVertexCount - 1;
133
if
( vid.
vertex
< vertexOffset + adjustedCount )
134
{
135
if
(
const
QgsNurbsCurve
*nurbs =
qgsgeometry_cast<const QgsNurbsCurve *>
( curve ) )
136
{
137
localIndex = vid.
vertex
- vertexOffset;
138
return
nurbs;
139
}
140
return
nullptr
;
141
}
142
vertexOffset += adjustedCount;
143
}
144
}
145
146
// Curve polygon - check exterior and interior rings
147
if
(
const
QgsCurvePolygon
*polygon =
qgsgeometry_cast<const QgsCurvePolygon *>
( geom ) )
148
{
149
const
QgsCurve
*ring =
nullptr
;
150
if
( vid.
ring
== 0 )
151
ring = polygon->exteriorRing();
152
else
if
( vid.
ring
> 0 && vid.
ring
<= polygon->numInteriorRings() )
153
ring = polygon->interiorRing( vid.
ring
- 1 );
154
155
if
( ring )
156
return
findNurbsCurveForVertex
( ring,
QgsVertexId
( 0, 0, vid.
vertex
), localIndex );
157
}
158
159
// Geometry collection
160
if
(
const
QgsGeometryCollection
*collection =
qgsgeometry_cast<const QgsGeometryCollection *>
( geom ) )
161
{
162
if
( vid.
part
>= 0 && vid.
part
< collection->numGeometries() )
163
{
164
return
findNurbsCurveForVertex
( collection->geometryN( vid.
part
),
QgsVertexId
( 0, vid.
ring
, vid.
vertex
), localIndex );
165
}
166
}
167
168
return
nullptr
;
169
}
170
171
QgsNurbsCurve
*
QgsNurbsUtils::findNurbsCurveForVertex
(
QgsAbstractGeometry
*geom,
const
QgsVertexId
&vid,
int
&localIndex )
172
{
173
return
const_cast<
QgsNurbsCurve
*
>
(
findNurbsCurveForVertex
(
const_cast<
const
QgsAbstractGeometry
*
>
( geom ), vid, localIndex ) );
174
}
QgsAbstractGeometry
Abstract base class for all geometries.
Definition
qgsabstractgeometry.h:82
QgsCompoundCurve
Compound curve geometry type.
Definition
qgscompoundcurve.h:35
QgsCurvePolygon
Curve polygon geometry type.
Definition
qgscurvepolygon.h:41
QgsCurve
Abstract base class for curved geometry type.
Definition
qgscurve.h:36
QgsCurve::numPoints
virtual int numPoints() const =0
Returns the number of points in the curve.
QgsGeometryCollection
Geometry collection.
Definition
qgsgeometrycollection.h:36
QgsNurbsCurve
Represents a NURBS (Non-Uniform Rational B-Spline) curve geometry in 2D/3D.
Definition
qgsnurbscurve.h:45
QgsNurbsUtils::containsNurbsCurve
static bool containsNurbsCurve(const QgsAbstractGeometry *geom)
Returns true if the geom contains a NURBS curve (recursively).
Definition
qgsnurbsutils.cpp:26
QgsNurbsUtils::extractNurbsCurve
static const QgsNurbsCurve * extractNurbsCurve(const QgsAbstractGeometry *geom)
Extracts the first NURBS curve found in the geom (recursively).
Definition
qgsnurbsutils.cpp:66
QgsNurbsUtils::findNurbsCurveForVertex
static const QgsNurbsCurve * findNurbsCurveForVertex(const QgsAbstractGeometry *geom, const QgsVertexId &vid, int &localIndex)
Finds the NURBS curve containing the vertex identified by vid.
Definition
qgsnurbsutils.cpp:110
qgsgeometry_cast
T qgsgeometry_cast(QgsAbstractGeometry *geom)
Definition
qgsabstractgeometry.h:1242
qgscompoundcurve.h
qgscurvepolygon.h
qgsgeometrycollection.h
qgsnurbscurve.h
qgsnurbsutils.h
qgsvertexid.h
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition
qgsvertexid.h:35
QgsVertexId::vertex
int vertex
Vertex number.
Definition
qgsvertexid.h:102
QgsVertexId::part
int part
Part number.
Definition
qgsvertexid.h:96
QgsVertexId::ring
int ring
Ring number.
Definition
qgsvertexid.h:99
Generated on
for QGIS API Documentation by
1.17.0