Jpp
 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 "JIO/JSerialisable.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JUTM {}
17 namespace JPP { using namespace JUTM; }
18 
19 /**
20  * Auxiliaries for handling universal transverse mercator coordinate system (UTM).
21  */
22 namespace JUTM {
23 
26  using JIO::JReader;
27  using JIO::JWriter;
28 
29 
30  /**
31  * Data structure for UTM position.
32  * The z-coordinate corresponds to the depth where <tt>z = 0</tt> is at sea level.
33  */
34  class JUTMPosition :
35  public JMATH::JMath<JUTMPosition>
36  {
37  public:
38  /**
39  * Default constructor.
40  */
42  east (0.0),
43  north(0.0),
44  z (0.0)
45  {}
46 
47 
48  /**
49  * Constructor.
50  *
51  * \param pos UTM position
52  */
53  JUTMPosition(const JVector3D& pos) :
54  east (pos.getX()),
55  north(pos.getY()),
56  z (pos.getZ())
57  {}
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param east UTM East
64  * \param north UTM North
65  * \param z UTM Z
66  */
67  JUTMPosition(const double east,
68  const double north,
69  const double z)
70  {
71  this->east = east;
72  this->north = north;
73  this->z = z;
74  }
75 
76 
77  /**
78  * Get UTM position.
79  *
80  * \return position
81  */
83  {
84  return static_cast<const JUTMPosition&>(*this);
85  }
86 
87 
88  /**
89  * Get position.
90  *
91  * \return position
92  */
94  {
95  return JPosition3D(east, north, z);
96  }
97 
98 
99  /**
100  * Type conversion operator.
101  *
102  * \return position
103  */
104  operator JPosition3D() const
105  {
106  return getPosition();
107  }
108 
109 
110  /**
111  * Get UTM east.
112  *
113  * \return UTM East
114  */
115  double getUTMEast() const
116  {
117  return this->east;
118  }
119 
120 
121  /**
122  * Get UTM north.
123  *
124  * \return UTM North
125  */
126  double getUTMNorth() const
127  {
128  return this->north;
129  }
130 
131 
132  /**
133  * Get UTM Z.
134  *
135  * \return UTM Z
136  */
137  double getUTMZ() const
138  {
139  return this->z;
140  }
141 
142 
143  /**
144  * Negate UTM position.
145  *
146  * \return this UTM position
147  */
149  {
150  east = -east;
151  north = -north;
152  z = -z;
153 
154  return *this;
155  }
156 
157 
158  /**
159  * Add UTM position.
160  *
161  * \param pos UTM position
162  * \return this UTM position
163  */
165  {
166  east += pos.getUTMEast();
167  north += pos.getUTMNorth();
168  z += pos.getUTMZ();
169 
170  return *this;
171  }
172 
173 
174  /**
175  * Subtract UTM position.
176  *
177  * \param pos UTM position
178  * \return this UTM position
179  */
181  {
182  east -= pos.getUTMEast();
183  north -= pos.getUTMNorth();
184  z -= pos.getUTMZ();
185 
186  return *this;
187  }
188 
189 
190  /**
191  * Scale UTM position.
192  *
193  * \param factor multiplication factor
194  * \return this UTM position
195  */
196  JUTMPosition& mul(const double factor)
197  {
198  east *= factor;
199  north *= factor;
200  z *= factor;
201 
202  return *this;
203  }
204 
205 
206  /**
207  * Scale UTM position.
208  *
209  * \param factor division factor
210  * \return this UTM position
211  */
212  JUTMPosition& div(const double factor)
213  {
214  east /= factor;
215  north /= factor;
216  z /= factor;
217 
218  return *this;
219  }
220 
221 
222  /**
223  * Read UTM position from input.
224  *
225  * \param in input stream
226  * \param pos UTM position
227  * \return input stream
228  */
229  friend inline std::istream& operator>>(std::istream& in, JUTMPosition& pos)
230  {
231  return in >> pos.east >> pos.north >> pos.z;
232  }
233 
234 
235  /**
236  * Write UTM position to output.
237  *
238  * \param out output stream
239  * \param pos UTM position
240  * \return output stream
241  */
242  friend inline std::ostream& operator<<(std::ostream& out, const JUTMPosition& pos)
243  {
244  return out << pos.east << ' ' << pos.north << ' ' << pos.z;
245  }
246 
247 
248 
249  /**
250  * Read UTM position from input.
251  *
252  * \param in input stream
253  * \param pos UTM position
254  * \return input stream
255  */
256  friend inline JReader& operator>>(JReader& in, JUTMPosition& pos)
257  {
258  return in >> pos.east >> pos.north >> pos.z;
259  }
260 
261 
262  /**
263  * Write UTM position to output.
264  *
265  * \param out output stream
266  * \param pos UTM position
267  * \return output stream
268  */
269  friend inline JWriter& operator<<(JWriter& out, const JUTMPosition& pos)
270  {
271  return out << pos.east << pos.north << pos.z;
272  }
273 
274 
275  protected:
276  double east;
277  double north;
278  double z;
279  };
280 }
281 
282 #endif
JUTMPosition & negate()
Negate UTM position.
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:26
JUTMPosition & sub(const JUTMPosition &pos)
Subtract UTM position.
const JUTMPosition & getUTMPosition() const
Get UTM position.
Definition: JUTMPosition.hh:82
JUTMPosition()
Default constructor.
Definition: JUTMPosition.hh:41
double getUTMEast() const
Get UTM east.
friend JWriter & operator<<(JWriter &out, const JUTMPosition &pos)
Write UTM position to output.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
friend JReader & operator>>(JReader &in, JUTMPosition &pos)
Read UTM position from input.
Data structure for UTM position.
Definition: JUTMPosition.hh:34
double getUTMZ() const
Get UTM Z.
double getUTMNorth() const
Get UTM north.
Data structure for vector in three dimensions.
Definition: JVector3D.hh:33
JUTMPosition & mul(const double factor)
Scale UTM position.
Interface for binary input.
JUTMPosition(const JVector3D &pos)
Constructor.
Definition: JUTMPosition.hh:53
JPosition3D getPosition() const
Get position.
Definition: JUTMPosition.hh:93
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:35
friend std::ostream & operator<<(std::ostream &out, const JUTMPosition &pos)
Write UTM position to output.
JUTMPosition(const double east, const double north, const double z)
Constructor.
Definition: JUTMPosition.hh:67