Jpp  15.0.5
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JUTMPosition.hh
Go to the documentation of this file.
1 #ifndef __JUTM__JUTMPOSITION__
2 #define __JUTM__JUTMPOSITION__
3 
4 #include <istream>
5 #include <ostream>
6 
8 #include "JMath/JMath.hh"
9 #include "JLang/JManip.hh"
10 #include "JIO/JSerialisable.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JUTM {}
18 namespace JPP { using namespace JUTM; }
19 
20 /**
21  * Auxiliaries for handling universal transverse mercator coordinate system (UTM).
22  */
23 namespace JUTM {
24 
25  using JMATH::JMath;
28  using JIO::JReader;
29  using JIO::JWriter;
30 
31 
32  /**
33  * Data structure for UTM position.
34  * The z-coordinate corresponds to the depth where <tt>z = 0</tt> is at sea level.
35  */
36  class JUTMPosition :
37  public JMath<JUTMPosition>
38  {
39  public:
40  /**
41  * Default constructor.
42  */
44  east (0.0),
45  north(0.0),
46  z (0.0)
47  {}
48 
49 
50  /**
51  * Constructor.
52  *
53  * \param pos UTM position
54  */
55  JUTMPosition(const JVector3D& pos) :
56  east (pos.getX()),
57  north(pos.getY()),
58  z (pos.getZ())
59  {}
60 
61 
62  /**
63  * Constructor.
64  *
65  * \param east UTM East
66  * \param north UTM North
67  * \param z UTM Z
68  */
69  JUTMPosition(const double east,
70  const double north,
71  const double z)
72  {
73  this->east = east;
74  this->north = north;
75  this->z = z;
76  }
77 
78 
79  /**
80  * Get UTM position.
81  *
82  * \return position
83  */
85  {
86  return static_cast<const JUTMPosition&>(*this);
87  }
88 
89 
90  /**
91  * Set UTM position.
92  *
93  * \param position position
94  */
95  void setUTMPosition(const JUTMPosition& position)
96  {
97  static_cast<JUTMPosition&>(*this) = position;
98  }
99 
100 
101  /**
102  * Get position.
103  *
104  * \return position
105  */
107  {
108  return JPosition3D(east, north, z);
109  }
110 
111 
112  /**
113  * Type conversion operator.
114  *
115  * \return position
116  */
117  operator JPosition3D() const
118  {
119  return getPosition();
120  }
121 
122 
123  /**
124  * Get UTM east.
125  *
126  * \return UTM East
127  */
128  double getUTMEast() const
129  {
130  return this->east;
131  }
132 
133 
134  /**
135  * Get UTM north.
136  *
137  * \return UTM North
138  */
139  double getUTMNorth() const
140  {
141  return this->north;
142  }
143 
144 
145  /**
146  * Get UTM Z.
147  *
148  * \return UTM Z
149  */
150  double getUTMZ() const
151  {
152  return this->z;
153  }
154 
155 
156  /**
157  * Negate UTM position.
158  *
159  * \return this UTM position
160  */
162  {
163  east = -east;
164  north = -north;
165  z = -z;
166 
167  return *this;
168  }
169 
170 
171  /**
172  * Add UTM position.
173  *
174  * \param pos UTM position
175  * \return this UTM position
176  */
178  {
179  east += pos.getUTMEast();
180  north += pos.getUTMNorth();
181  z += pos.getUTMZ();
182 
183  return *this;
184  }
185 
186 
187  /**
188  * Subtract UTM position.
189  *
190  * \param pos UTM position
191  * \return this UTM position
192  */
194  {
195  east -= pos.getUTMEast();
196  north -= pos.getUTMNorth();
197  z -= pos.getUTMZ();
198 
199  return *this;
200  }
201 
202 
203  /**
204  * Scale UTM position.
205  *
206  * \param factor multiplication factor
207  * \return this UTM position
208  */
209  JUTMPosition& mul(const double factor)
210  {
211  east *= factor;
212  north *= factor;
213  z *= factor;
214 
215  return *this;
216  }
217 
218 
219  /**
220  * Scale UTM position.
221  *
222  * \param factor division factor
223  * \return this UTM position
224  */
225  JUTMPosition& div(const double factor)
226  {
227  east /= factor;
228  north /= factor;
229  z /= factor;
230 
231  return *this;
232  }
233 
234 
235  /**
236  * Get displacement to position.
237  *
238  * The displacement corresponds to the 2D distance in the (East,North) plane.
239  *
240  * \param position position
241  * \return displacement
242  */
243  double getDisplacement(const JUTMPosition& position) const
244  {
245  const double x = this->getUTMEast() - position.getUTMEast();
246  const double y = this->getUTMNorth() - position.getUTMNorth();
247 
248  return sqrt(x*x + y*y);
249  }
250 
251 
252  /**
253  * Read UTM position from input.
254  *
255  * \param in input stream
256  * \param pos UTM position
257  * \return input stream
258  */
259  friend inline std::istream& operator>>(std::istream& in, JUTMPosition& pos)
260  {
261  return in >> pos.east >> pos.north >> pos.z;
262  }
263 
264 
265  /**
266  * Write UTM position to output.
267  *
268  * \param out output stream
269  * \param pos UTM position
270  * \return output stream
271  */
272  friend inline std::ostream& operator<<(std::ostream& out, const JUTMPosition& pos)
273  {
274  const JFormat format[] = { JFormat(out, getFormat<JUTMPosition>(JFormat_t(12, 3, std::ios::fixed | std::ios::showpos))),
275  JFormat(out, getFormat<JPosition3D> (JFormat_t( 9, 3, std::ios::fixed | std::ios::showpos))) };
276 
277  return out << format[0] << pos.east << ' '
278  << format[0] << pos.north << ' '
279  << format[1] << pos.z;
280  }
281 
282 
283 
284  /**
285  * Read UTM position from input.
286  *
287  * \param in input stream
288  * \param pos UTM position
289  * \return input stream
290  */
291  friend inline JReader& operator>>(JReader& in, JUTMPosition& pos)
292  {
293  return in >> pos.east >> pos.north >> pos.z;
294  }
295 
296 
297  /**
298  * Write UTM position to output.
299  *
300  * \param out output stream
301  * \param pos UTM position
302  * \return output stream
303  */
304  friend inline JWriter& operator<<(JWriter& out, const JUTMPosition& pos)
305  {
306  return out << pos.east << pos.north << pos.z;
307  }
308 
309 
310  protected:
311  double east;
312  double north;
313  double z;
314  };
315 
316 
317  static const JUTMPosition JNorth_t(0,+1,0); //!< North
318  static const JUTMPosition JEast_t (+1,0,0); //!< East
319  static const JUTMPosition JSouth_t(0,-1,0); //!< South
320  static const JUTMPosition JWest_t (-1,0,0); //!< West
321 }
322 
323 #endif
JUTMPosition & negate()
Negate UTM position.
static const JUTMPosition JNorth_t(0,+1, 0)
North.
Interface for binary output.
JUTMPosition & div(const double factor)
Scale UTM position.
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:110
JUTMPosition & sub(const JUTMPosition &pos)
Subtract UTM position.
const JUTMPosition & getUTMPosition() const
Get UTM position.
Definition: JUTMPosition.hh:84
double getDisplacement(const JUTMPosition &position) const
Get displacement to position.
JUTMPosition()
Default constructor.
Definition: JUTMPosition.hh:43
double getUTMEast() const
Get UTM east.
friend JWriter & operator<<(JWriter &out, const JUTMPosition &pos)
Write UTM position to output.
friend JReader & operator>>(JReader &in, JUTMPosition &pos)
Read UTM position from input.
void setUTMPosition(const JUTMPosition &position)
Set UTM position.
Definition: JUTMPosition.hh:95
static const JUTMPosition JSouth_t(0,-1, 0)
South.
Data structure for UTM position.
Definition: JUTMPosition.hh:36
double getUTMZ() const
Get UTM Z.
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:632
static const JUTMPosition JWest_t(-1, 0, 0)
West.
double getUTMNorth() const
Get UTM north.
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
JUTMPosition & mul(const double factor)
Scale UTM position.
Interface for binary input.
I/O manipulators.
JUTMPosition(const JVector3D &pos)
Constructor.
Definition: JUTMPosition.hh:55
JPosition3D getPosition() const
Get position.
Base class for data structures with artithmetic capabilities.
JUTMPosition & add(const JUTMPosition &pos)
Add UTM position.
friend std::istream & operator>>(std::istream &in, JUTMPosition &pos)
Read UTM position from input.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
friend std::ostream & operator<<(std::ostream &out, const JUTMPosition &pos)
Write UTM position to output.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
Data structure for format specifications.
Definition: JManip.hh:522
static const JUTMPosition JEast_t(+1, 0, 0)
East.
JUTMPosition(const double east, const double north, const double z)
Constructor.
Definition: JUTMPosition.hh:69