Jpp  18.5.2
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(this->getX(), this->getY(), this->getZ());
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  * Get x.
158  *
159  * \return UTM East
160  */
161  double getX() const
162  {
163  return this->east;
164  }
165 
166 
167  /**
168  * Get y.
169  *
170  * \return UTM North
171  */
172  double getY() const
173  {
174  return this->north;
175  }
176 
177 
178  /**
179  * Get z.
180  *
181  * \return UTM Z
182  */
183  double getZ() const
184  {
185  return this->z;
186  }
187 
188 
189  /**
190  * Negate UTM position.
191  *
192  * \return this UTM position
193  */
195  {
196  east = -east;
197  north = -north;
198  z = -z;
199 
200  return *this;
201  }
202 
203 
204  /**
205  * Add UTM position.
206  *
207  * \param pos UTM position
208  * \return this UTM position
209  */
211  {
212  east += pos.getUTMEast();
213  north += pos.getUTMNorth();
214  z += pos.getUTMZ();
215 
216  return *this;
217  }
218 
219 
220  /**
221  * Subtract UTM position.
222  *
223  * \param pos UTM position
224  * \return this UTM position
225  */
227  {
228  east -= pos.getUTMEast();
229  north -= pos.getUTMNorth();
230  z -= pos.getUTMZ();
231 
232  return *this;
233  }
234 
235 
236  /**
237  * Scale UTM position.
238  *
239  * \param factor multiplication factor
240  * \return this UTM position
241  */
242  JUTMPosition& mul(const double factor)
243  {
244  east *= factor;
245  north *= factor;
246  z *= factor;
247 
248  return *this;
249  }
250 
251 
252  /**
253  * Scale UTM position.
254  *
255  * \param factor division factor
256  * \return this UTM position
257  */
258  JUTMPosition& div(const double factor)
259  {
260  east /= factor;
261  north /= factor;
262  z /= factor;
263 
264  return *this;
265  }
266 
267 
268  /**
269  * Get displacement to position.
270  *
271  * The displacement corresponds to the 2D distance in the (East,North) plane.
272  *
273  * \param position position
274  * \return displacement
275  */
276  double getDisplacement(const JUTMPosition& position) const
277  {
278  const double x = this->getUTMEast() - position.getUTMEast();
279  const double y = this->getUTMNorth() - position.getUTMNorth();
280 
281  return sqrt(x*x + y*y);
282  }
283 
284 
285  /**
286  * Read UTM position from input.
287  *
288  * \param in input stream
289  * \param pos UTM position
290  * \return input stream
291  */
292  friend inline std::istream& operator>>(std::istream& in, JUTMPosition& pos)
293  {
294  return in >> pos.east >> pos.north >> pos.z;
295  }
296 
297 
298  /**
299  * Write UTM position to output.
300  *
301  * \param out output stream
302  * \param pos UTM position
303  * \return output stream
304  */
305  friend inline std::ostream& operator<<(std::ostream& out, const JUTMPosition& pos)
306  {
307  const JFormat format[] = { JFormat(out, getFormat<JUTMPosition>(JFormat_t(12, 3, std::ios::fixed | std::ios::showpos))),
308  JFormat(out, getFormat<JPosition3D> (JFormat_t( 9, 3, std::ios::fixed | std::ios::showpos))) };
309 
310  return out << format[0] << pos.east << ' '
311  << format[0] << pos.north << ' '
312  << format[1] << pos.z;
313  }
314 
315 
316 
317  /**
318  * Read UTM position from input.
319  *
320  * \param in input stream
321  * \param pos UTM position
322  * \return input stream
323  */
324  friend inline JReader& operator>>(JReader& in, JUTMPosition& pos)
325  {
326  return in >> pos.east >> pos.north >> pos.z;
327  }
328 
329 
330  /**
331  * Write UTM position to output.
332  *
333  * \param out output stream
334  * \param pos UTM position
335  * \return output stream
336  */
337  friend inline JWriter& operator<<(JWriter& out, const JUTMPosition& pos)
338  {
339  return out << pos.east << pos.north << pos.z;
340  }
341 
342 
343  protected:
344  double east;
345  double north;
346  double z;
347  };
348 
349 
350  static const JUTMPosition JNorth_t(0,+1,0); //!< North
351  static const JUTMPosition JEast_t (+1,0,0); //!< East
352  static const JUTMPosition JSouth_t(0,-1,0); //!< South
353  static const JUTMPosition JWest_t (-1,0,0); //!< West
354 }
355 
356 #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:109
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.
double getZ() const
Get z.
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:634
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
double getY() const
Get y.
JUTMPosition & mul(const double factor)
Scale UTM position.
Interface for binary input.
I/O manipulators.
double getX() const
Get x.
JUTMPosition(const JVector3D &pos)
Constructor.
Definition: JUTMPosition.hh:55
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
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.
Data structure for format specifications.
Definition: JManip.hh:524
static const JUTMPosition JEast_t(+1, 0, 0)
East.
JUTMPosition(const double east, const double north, const double z)
Constructor.
Definition: JUTMPosition.hh:69