Skip to content

Commit d02ea60

Browse files
author
Davide Faconti
committed
make static methods that ought to be static. Check if was intialized otherwise
1 parent c619b7f commit d02ea60

File tree

1 file changed

+60
-18
lines changed

1 file changed

+60
-18
lines changed

include/geodetic_utils/geodetic_conv.hpp

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class GeodeticConverter
3434

3535
void getReference(double* latitude, double* longitude, double* altitude)
3636
{
37+
if( !isInitialised() )
38+
{
39+
throw std::runtime_error("Illegal method call if not initialized");
40+
}
3741
*latitude = initial_latitude_;
3842
*longitude = initial_longitude_;
3943
*altitude = initial_altitude_;
@@ -58,8 +62,15 @@ class GeodeticConverter
5862
haveReference_ = true;
5963
}
6064

61-
void geodetic2Ecef(const double latitude, const double longitude, const double altitude, double* x,
62-
double* y, double* z)
65+
// added just to keep the old API
66+
inline void geodetic2Ecef(const double latitude, const double longitude, const double altitude,
67+
double* x, double* y, double* z)
68+
{
69+
Geodetic2Ecef(latitude, longitude, altitude, x, y, z);
70+
}
71+
72+
static void Geodetic2Ecef(const double latitude, const double longitude, const double altitude,
73+
double* x, double* y, double* z)
6374
{
6475
// Convert geodetic coordinates to ECEF.
6576
// http://code.google.com/p/pysatel/source/browse/trunk/coord.py?r=22
@@ -71,8 +82,15 @@ class GeodeticConverter
7182
*z = (kSemimajorAxis / xi * (1 - kFirstEccentricitySquared) + altitude) * sin(lat_rad);
7283
}
7384

74-
void ecef2Geodetic(const double x, const double y, const double z, double* latitude,
75-
double* longitude, double* altitude)
85+
// added just to keep the old API.
86+
inline void ecef2Geodetic(const double x, const double y, const double z,
87+
double* latitude, double* longitude, double* altitude)
88+
{
89+
Ecef2Geodetic(x, y, z, latitude, longitude, altitude);
90+
}
91+
92+
static void Ecef2Geodetic(const double x, const double y, const double z,
93+
double* latitude, double* longitude, double* altitude)
7694
{
7795
// Convert ECEF coordinates to geodetic coordinates.
7896
// J. Zhu, "Conversion of Earth-centered Earth-fixed coordinates
@@ -100,9 +118,13 @@ class GeodeticConverter
100118
*longitude = rad2Deg(atan2(y, x));
101119
}
102120

103-
void ecef2Ned(const double x, const double y, const double z, double* north, double* east,
104-
double* down)
121+
void ecef2Ned(const double x, const double y, const double z,
122+
double* north, double* east, double* down)
105123
{
124+
if( !isInitialised() )
125+
{
126+
throw std::runtime_error("Illegal method call if not initialized");
127+
}
106128
// Converts ECEF coordinate position into local-tangent-plane NED.
107129
// Coordinates relative to given ECEF coordinate frame.
108130

@@ -116,9 +138,13 @@ class GeodeticConverter
116138
*down = -ret(2);
117139
}
118140

119-
void ned2Ecef(const double north, const double east, const double down, double* x, double* y,
120-
double* z)
141+
void ned2Ecef(const double north, const double east, const double down,
142+
double* x, double* y, double* z)
121143
{
144+
if( !isInitialised() )
145+
{
146+
throw std::runtime_error("Illegal method call if not initialized");
147+
}
122148
// NED (north/east/down) to ECEF coordinates
123149
Eigen::Vector3d ned, ret;
124150
ned(0) = north;
@@ -133,27 +159,39 @@ class GeodeticConverter
133159
void geodetic2Ned(const double latitude, const double longitude, const double altitude,
134160
double* north, double* east, double* down)
135161
{
162+
if( !isInitialised() )
163+
{
164+
throw std::runtime_error("Illegal method call if not initialized");
165+
}
136166
// Geodetic position to local NED frame
137167
double x, y, z;
138-
geodetic2Ecef(latitude, longitude, altitude, &x, &y, &z);
168+
Geodetic2Ecef(latitude, longitude, altitude, &x, &y, &z);
139169
ecef2Ned(x, y, z, north, east, down);
140170
}
141171

142172
void ned2Geodetic(const double north, const double east, const double down, double* latitude,
143173
double* longitude, double* altitude)
144174
{
175+
if( !isInitialised() )
176+
{
177+
throw std::runtime_error("Illegal method call if not initialized");
178+
}
145179
// Local NED position to geodetic coordinates
146180
double x, y, z;
147181
ned2Ecef(north, east, down, &x, &y, &z);
148-
ecef2Geodetic(x, y, z, latitude, longitude, altitude);
182+
Ecef2Geodetic(x, y, z, latitude, longitude, altitude);
149183
}
150184

151185
void geodetic2Enu(const double latitude, const double longitude, const double altitude,
152186
double* east, double* north, double* up)
153187
{
188+
if( !isInitialised() )
189+
{
190+
throw std::runtime_error("Illegal method call if not initialized");
191+
}
154192
// Geodetic position to local ENU frame
155193
double x, y, z;
156-
geodetic2Ecef(latitude, longitude, altitude, &x, &y, &z);
194+
Geodetic2Ecef(latitude, longitude, altitude, &x, &y, &z);
157195

158196
double aux_north, aux_east, aux_down;
159197
ecef2Ned(x, y, z, &aux_north, &aux_east, &aux_down);
@@ -163,21 +201,25 @@ class GeodeticConverter
163201
*up = -aux_down;
164202
}
165203

166-
void enu2Geodetic(const double east, const double north, const double up, double* latitude,
167-
double* longitude, double* altitude)
204+
void enu2Geodetic(const double east, const double north, const double up,
205+
double* latitude, double* longitude, double* altitude)
168206
{
207+
if( !isInitialised() )
208+
{
209+
throw std::runtime_error("Illegal method call if not initialized");
210+
}
169211
// Local ENU position to geodetic coordinates
170212

171213
const double aux_north = north;
172214
const double aux_east = east;
173215
const double aux_down = -up;
174216
double x, y, z;
175217
ned2Ecef(aux_north, aux_east, aux_down, &x, &y, &z);
176-
ecef2Geodetic(x, y, z, latitude, longitude, altitude);
218+
Ecef2Geodetic(x, y, z, latitude, longitude, altitude);
177219
}
178220

179221
private:
180-
inline Eigen::Matrix3d nRe(const double lat_radians, const double lon_radians)
222+
inline static Eigen::Matrix3d nRe(const double lat_radians, const double lon_radians)
181223
{
182224
const double sLat = sin(lat_radians);
183225
const double sLon = sin(lon_radians);
@@ -198,13 +240,13 @@ class GeodeticConverter
198240
return ret;
199241
}
200242

201-
inline
243+
inline static
202244
double rad2Deg(const double radians)
203245
{
204246
return (radians / M_PI) * 180.0;
205247
}
206248

207-
inline
249+
inline static
208250
double deg2Rad(const double degrees)
209251
{
210252
return (degrees / 180.0) * M_PI;
@@ -224,6 +266,6 @@ class GeodeticConverter
224266
bool haveReference_;
225267

226268
}; // class GeodeticConverter
227-
}; // namespace geodetic_conv
269+
} // namespace geodetic_conv
228270

229271
#endif // GEODETIC_CONVERTER_H_

0 commit comments

Comments
 (0)