OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimLsrSpace.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // DESCRIPTION:
6 // This class maintains the relationship between a local space rectangular
7 // (LSR) coordinate system and the earth-centered, earth-fixed (ECEF) system.
8 //
9 // SOFTWARE HISTORY:
10 //
11 // 09Aug2001 Oscar Kramer (okramer@imagelinks.com)
12 // Initial coding.
13 //
14 //*****************************************************************************
15 // $Id: ossimLsrSpace.cpp 17593 2010-06-17 19:07:26Z dburken $
16 
18 #include <ossim/base/ossimCommon.h>
19 #include <ossim/base/ossimGpt.h>
22 
23 
24 //*****************************************************************************
25 // CONSTRUCTOR: ossimLsrSpace(origin, x_dir, y_dir, int)
26 //
27 // Constructs the space given origin, and X and Y ECEF directions. The int
28 // argument is a place holder only and not used.
29 //
30 //*****************************************************************************
32  const ossimEcefVector& x_dir_ecf_vec,
33  const ossimEcefVector& y_dir_ecf_vec,
34  int /* z_not_provided_space_holder */)
35  : theOrigin (origin)
36 {
37  //***
38  // Compute the remaining axis given first two:
39  //***
40  ossimColumnVector3d xdir (x_dir_ecf_vec.data().unit());
41  ossimColumnVector3d ydir (y_dir_ecf_vec.data().unit());
42  ossimColumnVector3d zdir (xdir.cross(ydir));
43 
44  //***
45  // Fill the rotation matrix:
46  //***
47  theLsrToEcefRotMatrix = ossimMatrix3x3::create(xdir[0], ydir[0], zdir[0],
48  xdir[1], ydir[1], zdir[1],
49  xdir[2], ydir[2], zdir[2]);
50 }
51 
52 //*****************************************************************************
53 // CONSTRUCTOR: ossimLsrSpace
54 //
55 // Constructs the space given origin, and X and Z ECEF directions. The int
56 // argument is a place holder only and not used.
57 //
58 //*****************************************************************************
60  const ossimEcefVector& x_dir_ecf_vec,
61  int /* y_not_provided_space_holder */,
62  const ossimEcefVector& z_dir_ecf_vec)
63  : theOrigin (origin)
64 {
65  //***
66  // Compute the remaining axis given first two:
67  //***
68  ossimColumnVector3d xdir (x_dir_ecf_vec.data().unit());
69  ossimColumnVector3d zdir (z_dir_ecf_vec.data().unit());
70  ossimColumnVector3d ydir (zdir.cross(xdir));
71 
72  //***
73  // Fill the rotation matrix:
74  //***
75  theLsrToEcefRotMatrix = ossimMatrix3x3::create(xdir[0], ydir[0], zdir[0],
76  xdir[1], ydir[1], zdir[1],
77  xdir[2], ydir[2], zdir[2]);
78 }
79 
80 //*****************************************************************************
81 // CONSTRUCTOR: ossimLsrSpace
82 //
83 // Constructs the space given origin, and Y and Z ECEF directions. The int
84 // argument is a place holder only and not used.
85 //
86 //*****************************************************************************
88  int /* x_not_provided_space_holder */,
89  const ossimEcefVector& y_dir_ecf_vec,
90  const ossimEcefVector& z_dir_ecf_vec)
91  : theOrigin (origin)
92 {
93  //***
94  // Compute the remaining axis given first two:
95  //***
96  ossimColumnVector3d ydir (y_dir_ecf_vec.data().unit());
97  ossimColumnVector3d zdir (z_dir_ecf_vec.data().unit());
98  ossimColumnVector3d xdir (ydir.cross(zdir));
99 
100  //***
101  // Fill the rotation matrix:
102  //***
103  theLsrToEcefRotMatrix = ossimMatrix3x3::create(xdir[0], ydir[0], zdir[0],
104  xdir[1], ydir[1], zdir[1],
105  xdir[2], ydir[2], zdir[2]);
106 }
107 
108 //*****************************************************************************
109 // CONSTRUCTORS: ossimLsrSpace(ossimGpt, y_azimuth)
110 //
111 // This constructor sets up a local coordinate system centered at the
112 // specified groundpoint, with the Z-axis normal to the ellipsoid and the
113 // Y-axis rotated clockwise from north by the y_azimuth. This angle defaults
114 // to 0, producing an East-North-Up system.
115 //
116 //*****************************************************************************
118  const double& y_azimuth)
119 {
120  //***
121  // Convert ground point origin to ECEF coordinates:
122  //***
124 
125  //***
126  // Establish the component vectors for ENU system::
127  //***
128  double sin_lat = ossim::sind(origin.lat);
129  double cos_lat = ossim::cosd(origin.lat);
130  double sin_lon = ossim::sind(origin.lon);
131  double cos_lon = ossim::cosd(origin.lon);
132 
133  ossimColumnVector3d E (-sin_lon,
134  cos_lon,
135  0.0);
136  ossimColumnVector3d N (-sin_lat*cos_lon,
137  -sin_lat*sin_lon,
138  cos_lat);
139  ossimColumnVector3d U (E.cross(N));
140 
141  //
142  // Fill rotation matrix with these components, rotated about the Z axis
143  // by the azimuth indicated:
144  //
145  if (std::abs(y_azimuth) > FLT_EPSILON)
146  {
147  double cos_azim = ossim::cosd(y_azimuth);
148  double sin_azim = ossim::sind(y_azimuth);
149  ossimColumnVector3d X (cos_azim*E - sin_azim*N);
150  ossimColumnVector3d Y (sin_azim*E + cos_azim*N);
151  ossimColumnVector3d Z (X.cross(Y));
152 
154  = ossimMatrix3x3::create(X[0], Y[0], Z[0],
155  X[1], Y[1], Z[1],
156  X[2], Y[2], Z[2]);
157  }
158  else
159  {
160  //***
161  // No azimuth rotation, so simplify:
162  //***
164  E[1], N[1], U[1],
165  E[2], N[2], U[2]);
166  }
167 }
168 
169 //*****************************************************************************
170 // OPERATOR: ==
171 //*****************************************************************************
173 {
174  if (theOrigin != that.origin())
175  return false;
176 
178  return false;
179 
180  return true;
181 }
182 
183 //*****************************************************************************
184 // OPERATOR: =
185 //*****************************************************************************
187 {
188  theOrigin = space.theOrigin;
190  return *this;
191 }
192 
193 //*****************************************************************************
194 // STATIC METHOD: lsrSpaceErrorMessage()
195 //
196 // Convenience method accessible to all owners of an ossimLsrSpace for
197 // displaying an error message when LSR spaces do not match between
198 // objects. All operations between LSR objects must be in a common space.
199 //
200 //*****************************************************************************
202 {
203  os<<"ossimLsrSpace ERROR: An operation was attempted between two LSR \n"
204  <<" objects with differing LSR spaces. This is an illegal condition.\n"
205  <<" Please check the data and/or report the error to OSSIM development."
206  << std::endl;
207 
208  return os;
209 }
210 
211 //*****************************************************************************
212 // METHOD: print()
213 //
214 // Dumps contents to stream for debug purposes. Defaults to cout.
215 //
216 //*****************************************************************************
217 void ossimLsrSpace::print(ostream& stream) const
218 {
219  stream << "(ossimLsrSpace)"
220  << "\n theOrigin = " << theOrigin
221  << "\n theLsrToEcefRotMatrix = \n" << theLsrToEcefRotMatrix << std::endl;
222 }
223 
static ostream & lsrSpaceErrorMessage(ostream &os=ossimNotify(ossimNotifyLevel_INFO))
ossimColumnVector3d cross(const ossimColumnVector3d &rhs) const
const ossimLsrSpace & operator=(const ossimLsrSpace &space)
ossimColumnVector3d unit() const
double sind(double x)
Definition: ossimCommon.h:260
#define abs(a)
Definition: auxiliary.h:74
#define FLT_EPSILON
static NEWMAT::Matrix create()
double cosd(double x)
Definition: ossimCommon.h:259
bool operator==(const ossimLsrSpace &) const
const ossimEcefPoint & origin() const
ossimEcefPoint theOrigin
const ossimColumnVector3d & data() const
NEWMAT::Matrix theLsrToEcefRotMatrix
void print(ostream &stream=ossimNotify(ossimNotifyLevel_INFO)) const
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23