Jpp
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  * Get UTM east.
101  *
102  * \return UTM East
103  */
104  double getUTMEast() const
105  {
106  return this->east;
107  }
108 
109 
110  /**
111  * Get UTM north.
112  *
113  * \return UTM North
114  */
115  double getUTMNorth() const
116  {
117  return this->north;
118  }
119 
120 
121  /**
122  * Get UTM Z.
123  *
124  * \return UTM Z
125  */
126  double getUTMZ() const
127  {
128  return this->z;
129  }
130 
131 
132  /**
133  * Negate UTM position.
134  *
135  * \return this UTM position
136  */
138  {
139  east = -east;
140  north = -north;
141  z = -z;
142 
143  return *this;
144  }
145 
146 
147  /**
148  * Add UTM position.
149  *
150  * \param pos UTM position
151  * \return this UTM position
152  */
154  {
155  east += pos.getUTMEast();
156  north += pos.getUTMNorth();
157  z += pos.getUTMZ();
158 
159  return *this;
160  }
161 
162 
163  /**
164  * Subtract UTM position.
165  *
166  * \param pos UTM position
167  * \return this UTM position
168  */
170  {
171  east -= pos.getUTMEast();
172  north -= pos.getUTMNorth();
173  z -= pos.getUTMZ();
174 
175  return *this;
176  }
177 
178 
179  /**
180  * Scale UTM position.
181  *
182  * \param factor multiplication factor
183  * \return this UTM position
184  */
185  JUTMPosition& mul(const double factor)
186  {
187  east *= factor;
188  north *= factor;
189  z *= factor;
190 
191  return *this;
192  }
193 
194 
195  /**
196  * Scale UTM position.
197  *
198  * \param factor division factor
199  * \return this UTM position
200  */
201  JUTMPosition& div(const double factor)
202  {
203  east /= factor;
204  north /= factor;
205  z /= factor;
206 
207  return *this;
208  }
209 
210 
211  /**
212  * Read UTM position from input.
213  *
214  * \param in input stream
215  * \param pos UTM position
216  * \return input stream
217  */
218  friend inline std::istream& operator>>(std::istream& in, JUTMPosition& pos)
219  {
220  return in >> pos.east >> pos.north >> pos.z;
221  }
222 
223 
224  /**
225  * Write UTM position to output.
226  *
227  * \param out output stream
228  * \param pos UTM position
229  * \return output stream
230  */
231  friend inline std::ostream& operator<<(std::ostream& out, const JUTMPosition& pos)
232  {
233  return out << pos.east << ' ' << pos.north << ' ' << pos.z;
234  }
235 
236 
237 
238  /**
239  * Read UTM position from input.
240  *
241  * \param in input stream
242  * \param pos UTM position
243  * \return input stream
244  */
245  friend inline JReader& operator>>(JReader& in, JUTMPosition& pos)
246  {
247  return in >> pos.east >> pos.north >> pos.z;
248  }
249 
250 
251  /**
252  * Write UTM position to output.
253  *
254  * \param out output stream
255  * \param pos UTM position
256  * \return output stream
257  */
258  friend inline JWriter& operator<<(JWriter& out, const JUTMPosition& pos)
259  {
260  return out << pos.east << pos.north << pos.z;
261  }
262 
263 
264  protected:
265  double east;
266  double north;
267  double z;
268  };
269 }
270 
271 #endif
JUTM::JUTMPosition::div
JUTMPosition & div(const double factor)
Scale UTM position.
Definition: JUTMPosition.hh:201
JUTM::JUTMPosition::sub
JUTMPosition & sub(const JUTMPosition &pos)
Subtract UTM position.
Definition: JUTMPosition.hh:169
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JUTM::JUTMPosition::JUTMPosition
JUTMPosition()
Default constructor.
Definition: JUTMPosition.hh:41
JUTM::JUTMPosition::east
double east
Definition: JUTMPosition.hh:265
JPosition3D.hh
JUTM::JUTMPosition::getUTMZ
double getUTMZ() const
Get UTM Z.
Definition: JUTMPosition.hh:126
JUTM::JUTMPosition::mul
JUTMPosition & mul(const double factor)
Scale UTM position.
Definition: JUTMPosition.hh:185
JUTM::JUTMPosition::JUTMPosition
JUTMPosition(const double east, const double north, const double z)
Constructor.
Definition: JUTMPosition.hh:67
JUTM::JUTMPosition::add
JUTMPosition & add(const JUTMPosition &pos)
Add UTM position.
Definition: JUTMPosition.hh:153
JMATH::JMath
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:26
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JUTM::JUTMPosition::operator>>
friend std::istream & operator>>(std::istream &in, JUTMPosition &pos)
Read UTM position from input.
Definition: JUTMPosition.hh:218
JGEOMETRY3D::JVector3D
Data structure for vector in three dimensions.
Definition: JVector3D.hh:33
JSerialisable.hh
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JUTM::JUTMPosition::getPosition
JPosition3D getPosition() const
Get position.
Definition: JUTMPosition.hh:93
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:130
JUTM::JUTMPosition
Data structure for UTM position.
Definition: JUTMPosition.hh:34
JMath.hh
JUTM::JUTMPosition::operator<<
friend JWriter & operator<<(JWriter &out, const JUTMPosition &pos)
Write UTM position to output.
Definition: JUTMPosition.hh:258
JUTM::JUTMPosition::getUTMNorth
double getUTMNorth() const
Get UTM north.
Definition: JUTMPosition.hh:115
JUTM::JUTMPosition::operator<<
friend std::ostream & operator<<(std::ostream &out, const JUTMPosition &pos)
Write UTM position to output.
Definition: JUTMPosition.hh:231
JUTM::JUTMPosition::JUTMPosition
JUTMPosition(const JVector3D &pos)
Constructor.
Definition: JUTMPosition.hh:53
JUTM::JUTMPosition::operator>>
friend JReader & operator>>(JReader &in, JUTMPosition &pos)
Read UTM position from input.
Definition: JUTMPosition.hh:245
JUTM::JUTMPosition::north
double north
Definition: JUTMPosition.hh:266
JUTM::JUTMPosition::getUTMPosition
const JUTMPosition & getUTMPosition() const
Get UTM position.
Definition: JUTMPosition.hh:82
JUTM
Auxiliaries for handling universal transverse mercator coordinate system (UTM).
Definition: JUTMGrid.hh:18
JUTM::JUTMPosition::z
double z
Definition: JUTMPosition.hh:267
JUTM::JUTMPosition::getUTMEast
double getUTMEast() const
Get UTM east.
Definition: JUTMPosition.hh:104
JUTM::JUTMPosition::negate
JUTMPosition & negate()
Negate UTM position.
Definition: JUTMPosition.hh:137