Line data Source code
1 : /******************************************************************************
2 : * File: ogrdxf_polyline_smooth.h
3 : *
4 : * Project: Interpolation support for smooth POLYLINE and LWPOLYLINE entities.
5 : * Purpose: Definition of classes for OGR .dxf driver.
6 : * Author: TJ Snider, timsn@thtree.com
7 : * Ray Gardener, Daylon Graphics Ltd.
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 2010 Daylon Graphics Ltd.
11 : *
12 : * Permission is hereby granted, free of charge, to any person obtaining a
13 : * copy of this software and associated documentation files (the "Software"),
14 : * to deal in the Software without restriction, including without limitation
15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : * and/or sell copies of the Software, and to permit persons to whom the
17 : * Software is furnished to do so, subject to the following conditions:
18 : *
19 : * The above copyright notice and this permission notice shall be included
20 : * in all copies or substantial portions of the Software.
21 : *
22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 : * DEALINGS IN THE SOFTWARE.
29 : ****************************************************************************/
30 :
31 : #ifndef OGRDXF_SMOOTH_POLYLINE_H_INCLUDED
32 : #define OGRDXF_SMOOTH_POLYLINE_H_INCLUDED
33 :
34 : #include "ogrsf_frmts.h"
35 : #include "cpl_conv.h"
36 : #include <vector>
37 : #include "assert.h"
38 :
39 : class DXFSmoothPolylineVertex
40 : {
41 : public:
42 : double x;
43 : double y;
44 : double z;
45 : double bulge;
46 :
47 48 : DXFSmoothPolylineVertex()
48 48 : {
49 48 : x = y = z = bulge = 0.0;
50 48 : }
51 :
52 263 : DXFSmoothPolylineVertex(double dfX, double dfY, double dfZ, double dfBulge)
53 263 : {
54 263 : set(dfX, dfY, dfZ, dfBulge);
55 263 : }
56 :
57 263 : void set(double dfX, double dfY, double dfZ, double dfBulge)
58 : {
59 263 : x = dfX;
60 263 : y = dfY;
61 263 : z = dfZ;
62 263 : bulge = dfBulge;
63 263 : }
64 :
65 : void scale(double s)
66 : {
67 : x *= s;
68 : y *= s;
69 : }
70 :
71 12 : double length() const
72 : {
73 12 : return (sqrt(x * x + y * y));
74 : }
75 :
76 12 : void normalize()
77 : {
78 12 : const double len = length();
79 12 : assert(len != 0.0);
80 :
81 12 : x /= len;
82 12 : y /= len;
83 12 : }
84 :
85 41 : bool shares_2D_pos(const DXFSmoothPolylineVertex &v) const
86 : {
87 41 : return (x == v.x && y == v.y);
88 : }
89 : };
90 :
91 : // Quiet warning from gcc (possibly https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112370)
92 : #if defined(__GNUC__) && __GNUC__ >= 13
93 : #pragma GCC diagnostic push
94 : #pragma GCC diagnostic ignored "-Wfree-nonheap-object"
95 : #endif
96 : class DXFSmoothPolyline
97 : {
98 : // A DXF polyline that includes vertex bulge information.
99 : // Call Tessellate() to convert to an OGRGeometry.
100 : // We treat Z as constant over the entire string; this may
101 : // change in the future.
102 :
103 : private:
104 : std::vector<DXFSmoothPolylineVertex> m_vertices;
105 : mutable bool m_blinestringstarted;
106 : bool m_bClosed;
107 : int m_dim;
108 : bool m_bUseMaxGapWhenTessellatingArcs;
109 :
110 : public:
111 71 : DXFSmoothPolyline()
112 71 : : m_blinestringstarted(false), m_bClosed(false), m_dim(2),
113 71 : m_bUseMaxGapWhenTessellatingArcs(false)
114 : {
115 71 : }
116 :
117 : OGRGeometry *Tessellate() const;
118 :
119 170 : size_t size() const
120 : {
121 170 : return m_vertices.size();
122 : }
123 :
124 : void SetSize(int n)
125 : {
126 : m_vertices.reserve(n);
127 : }
128 :
129 263 : void AddPoint(double dfX, double dfY, double dfZ, double dfBulge)
130 : {
131 263 : m_vertices.push_back(DXFSmoothPolylineVertex(dfX, dfY, dfZ, dfBulge));
132 263 : }
133 :
134 : void Close();
135 :
136 71 : bool IsEmpty() const
137 : {
138 71 : return m_vertices.empty();
139 : }
140 :
141 137 : void setCoordinateDimension(int n)
142 : {
143 137 : m_dim = n;
144 137 : }
145 :
146 70 : void SetUseMaxGapWhenTessellatingArcs(bool bVal)
147 : {
148 70 : m_bUseMaxGapWhenTessellatingArcs = bVal;
149 70 : }
150 :
151 : private:
152 : void EmitArc(const DXFSmoothPolylineVertex &,
153 : const DXFSmoothPolylineVertex &, double radius, double len,
154 : double saggita, OGRLineString *, double dfZ = 0.0) const;
155 :
156 : void EmitLine(const DXFSmoothPolylineVertex &,
157 : const DXFSmoothPolylineVertex &, OGRLineString *) const;
158 : };
159 : #if defined(__GNUC__) && __GNUC__ >= 13
160 : #pragma GCC diagnostic pop
161 : #endif
162 :
163 : #endif /* OGRDXF_SMOOTH_POLYLINE_H_INCLUDED */
|