libosmscout 1.1.1
Loading...
Searching...
No Matches
Projection.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_UTIL_PROJECTION_H
2#define OSMSCOUT_UTIL_PROJECTION_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2010 Tim Teulings
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
24
25#include <osmscout/GeoCoord.h>
26#include <osmscout/Pixel.h>
27#include <osmscout/Point.h>
28
32
34
35namespace osmscout {
36
46 {
47 protected:
48 GeoCoord center;
49 double angle=0.0;
50 Magnification magnification;
51 double dpi=0.0;
52 size_t width=0;
53 size_t height=0;
54
55 GeoBox boundingBox;
56
57 double pixelSize=0.0;
58 double meterInPixel=0.0;
59 double meterInMM=0.0;
60
61 public:
62
67 {
68 public:
69 // this should be private, but that would exclude future projection
70 // implementors. I don't know a nice way to handle this
72#ifdef OSMSCOUT_HAVE_SSE2
73 int count=0;
74 ALIGN16_BEG double lon[2] ALIGN16_END;
75 ALIGN16_BEG double lat[2] ALIGN16_END;
76 double* xPointer[2]={nullptr,nullptr};
77 double* yPointer[2]={nullptr,nullptr};
78#endif
79
80 public:
85
86 BatchTransformer(const BatchTransformer& other) = delete;
88
90 {
91 Flush();
92 }
93
96
97 void GeoToPixel(const GeoCoord& coord,
98 double& x,
99 double& y)
100 {
101#ifdef OSMSCOUT_HAVE_SSE2
102 if (projection.CanBatch()) {
103 this->lon[count]=coord.GetLon();
104 this->lat[count]=coord.GetLat();
105 xPointer[count]=&x;
106 yPointer[count]=&y;
107 count++;
108
109 if (count==2) {
110 count=0;
111 projection.GeoToPixel(*this);
112 }
113 }
114 else {
115 Vertex2D pixel;
116 projection.GeoToPixel(coord,
117 pixel);
118 x=pixel.GetX();
119 y=pixel.GetY();
120 }
121#else
122 Vertex2D pixel;
123 projection.GeoToPixel(coord,
124 pixel);
125 x=pixel.GetX();
126 y=pixel.GetY();
127#endif
128 }
129
130 void GeoToPixel(const Point& coord,
131 double& x,
132 double& y)
133 {
134#ifdef OSMSCOUT_HAVE_SSE2
135 if (projection.CanBatch()) {
136 this->lon[count]=coord.GetCoord().GetLon();
137 this->lat[count]=coord.GetCoord().GetLat();
138 xPointer[count]=&x;
139 yPointer[count]=&y;
140 count++;
141
142 if (count==2) {
143 count=0;
144 projection.GeoToPixel(*this);
145 }
146 }
147 else {
148 Vertex2D pixel;
149 projection.GeoToPixel(coord.GetCoord(),
150 pixel);
151 x=pixel.GetX();
152 y=pixel.GetY();
153 }
154#else
155 Vertex2D pixel;
156 projection.GeoToPixel(coord.GetCoord(),
157 pixel);
158 x=pixel.GetX();
159 y=pixel.GetY();
160#endif
161 }
162
163 void Flush()
164 {
165#ifdef OSMSCOUT_HAVE_SSE2
166 if (count!=0) {
167 count=0;
168 Vertex2D pixel;
169 projection.GeoToPixel(GeoCoord(lat[0],
170 lon[0]),
171 pixel);
172
173 *xPointer[0]=pixel.GetX();
174 *yPointer[0]=pixel.GetY();
175 }
176#endif
177 }
178 };
179
180 Projection() = default;
181 Projection(const Projection&) = default;
182 Projection(Projection&&) = default;
183 Projection& operator=(const Projection&) = default;
185 virtual ~Projection() = default;
186
187 virtual bool CanBatch() const = 0;
188 virtual bool IsValid() const = 0;
189
193 virtual bool IsValidFor(const GeoCoord& coord) const = 0;
194
195 [[nodiscard]] GeoCoord GetCenter() const
196 {
197 return center;
198 }
199
204 [[nodiscard]] double GetAngle() const
205 {
206 return angle;
207 }
208
212 [[nodiscard]] size_t GetWidth() const
213 {
214 return width;
215 }
216
220 [[nodiscard]] size_t GetHeight() const
221 {
222 return height;
223 }
224
231 [[nodiscard]] ScreenBox GetScreenBox() const
232 {
233 return {Vertex2D(0.0,
234 0.0),
235 Vertex2D(static_cast<double>(GetWidth()),
236 static_cast<double>(GetHeight()))};
237 }
238
242 [[nodiscard]] Magnification GetMagnification() const
243 {
244 return magnification;
245 }
246
250 [[nodiscard]] double GetDPI() const
251 {
252 return dpi;
253 }
254
255 [[nodiscard]] GeoBox GetDimensions() const
256 {
257 return boundingBox;
258 }
259
263 [[nodiscard]] double GetPixelSize() const
264 {
265 return pixelSize;
266 }
267
271 [[nodiscard]] double GetMeterInPixel() const
272 {
273 return meterInPixel;
274 }
275
279 [[nodiscard]] double GetMeterInMM() const
280 {
281 return meterInMM;
282 }
283
292 [[nodiscard]] double ConvertWidthToPixel(double width) const
293 {
294 return width*dpi/25.4;
295 }
296
305 [[nodiscard]] double ConvertPixelToWidth(double pixel) const
306 {
307 return pixel*25.4/dpi;
308 }
309
317 virtual bool PixelToGeo(double x, double y,
318 GeoCoord& coord) const = 0;
319
326 virtual bool GeoToPixel(const GeoCoord& coord,
327 Vertex2D& pixel) const = 0;
328
335 bool BoundingBoxToPixel(const GeoBox& boundingBox,
336 ScreenBox& screenBox) const;
337
338 protected:
339 virtual void GeoToPixel(const BatchTransformer& transformData) const = 0;
340
341 friend class BatchTransformer;
342 };
343}
344
345#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Projection.h:67
BatchTransformer & operator=(const BatchTransformer &other)=delete
BatchTransformer(const BatchTransformer &other)=delete
BatchTransformer & operator=(BatchTransformer &&other)=delete
~BatchTransformer()
Definition Projection.h:89
void GeoToPixel(const GeoCoord &coord, double &x, double &y)
Definition Projection.h:97
BatchTransformer(BatchTransformer &&other)=delete
const Projection & projection
Definition Projection.h:71
BatchTransformer(const Projection &projection)
Definition Projection.h:81
void Flush()
Definition Projection.h:163
void GeoToPixel(const Point &coord, double &x, double &y)
Definition Projection.h:130
double GetPixelSize() const
Definition Projection.h:263
double pixelSize
Size of a pixel in meter.
Definition Projection.h:57
GeoCoord center
Coordinate of the center of the displayed area.
Definition Projection.h:48
size_t width
Width of image.
Definition Projection.h:52
virtual bool GeoToPixel(const GeoCoord &coord, Vertex2D &pixel) const =0
virtual bool IsValidFor(const GeoCoord &coord) const =0
size_t height
Height of image.
Definition Projection.h:53
GeoBox boundingBox
Bounding box of the current projection on the ground.
Definition Projection.h:55
friend class BatchTransformer
Definition Projection.h:341
virtual ~Projection()=default
double GetDPI() const
Definition Projection.h:250
Projection & operator=(const Projection &)=default
double GetMeterInMM() const
Definition Projection.h:279
double angle
Display rotation angle in radians, canvas clockwise.
Definition Projection.h:49
double dpi
Screen DPI.
Definition Projection.h:51
Projection & operator=(Projection &&)=default
bool BoundingBoxToPixel(const GeoBox &boundingBox, ScreenBox &screenBox) const
double ConvertPixelToWidth(double pixel) const
Definition Projection.h:305
double GetMeterInPixel() const
Definition Projection.h:271
size_t GetWidth() const
Definition Projection.h:212
ScreenBox GetScreenBox() const
Definition Projection.h:231
virtual bool IsValid() const =0
GeoBox GetDimensions() const
Definition Projection.h:255
double meterInPixel
Number of on screen pixel for one meter on the ground.
Definition Projection.h:58
double meterInMM
Number of on screen millimeters for one meter on the ground.
Definition Projection.h:59
Projection(Projection &&)=default
double GetAngle() const
Definition Projection.h:204
GeoCoord GetCenter() const
Definition Projection.h:195
virtual bool CanBatch() const =0
virtual bool PixelToGeo(double x, double y, GeoCoord &coord) const =0
size_t GetHeight() const
Definition Projection.h:220
double ConvertWidthToPixel(double width) const
Definition Projection.h:292
Magnification GetMagnification() const
Definition Projection.h:242
virtual void GeoToPixel(const BatchTransformer &transformData) const =0
Magnification magnification
Current magnification.
Definition Projection.h:50
Projection(const Projection &)=default
Definition Area.h:39