OverSim
CoordinateSystem.cc
Go to the documentation of this file.
1 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH)
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 
23 #include <ProxNodeHandle.h>
24 
25 #include <CoordinateSystem.h>
26 
27 
29 
31 {
32  if (!dynamic_cast<const EuclideanNcsNodeInfo*>(&abstractInfo)) {
33  return Prox::PROX_UNKNOWN;
34  }
35  const EuclideanNcsNodeInfo& info =
36  *(static_cast<const EuclideanNcsNodeInfo*>(&abstractInfo));
37 
38  double dist = 0.0;
39 
40  for (uint8_t i = 0; i < info.getDimension(); ++i) {
41  dist += pow(getCoords(i) - info.getCoords(i), 2);
42  }
43  dist = sqrt(dist) / 1000;
44  // old calculation based on s not ms
45  // dist = sqrt(dist);
46 
47  return Prox(dist, 0.7); //TODO
48 }
49 
51 {
52  if (!dynamic_cast<const GnpNpsCoordsInfo*>(&abstractInfo)) return false;
53 
54  const GnpNpsCoordsInfo& temp =
55  static_cast<const GnpNpsCoordsInfo&>(abstractInfo);
56 
57  coordinates = temp.coordinates;
58  npsLayer = temp.npsLayer;
59 
60  return true;
61 }
62 
63 GnpNpsCoordsInfo::operator Coords() const
64 {
65  Coords temp;
66  for (uint8_t i = 0; i < coordinates.size(); ++i) {
67  temp.push_back(coordinates[i]);
68  }
69  temp.push_back(npsLayer);
70 
71  return temp;
72 }
73 
74 std::ostream& operator<<(std::ostream& os, const GnpNpsCoordsInfo& info)
75 {
76  if (!info.getCoords().size()) throw cRuntimeError("dim = 0");
77 
78  /*
79  os << "< ";
80  uint8_t i;
81  for (i = 0; i < info.getCoords().size() - 1; ++i) {
82  os << info.getCoords(i) << ", ";
83  }
84  os << info.getCoords(i) << " >";
85  */
86  os << info.getCoords();
87  if (info.getLayer() != -1)
88  os << ", NPS-Layer = " << (int)info.getLayer();
89 
90  return os;
91 }
92 
94 {
95  if (!dynamic_cast<const VivaldiCoordsInfo*>(&abstractInfo)) {
96  return Prox::PROX_UNKNOWN;
97  }
98  const VivaldiCoordsInfo& info =
99  *(static_cast<const VivaldiCoordsInfo*>(&abstractInfo));
100 
101  double dist = 0.0, accuracy = 0.0;
102 
103  for (uint8_t i = 0; i < info.getDimension(); ++i) {
104  dist += pow(getCoords(i) - info.getCoords(i), 2);
105  }
106  dist = sqrt(dist) / 1000;
107 
108  accuracy = 1 - ((info.getError() + getError()) / 2);
109  if (info.getError() >= 1.0 || getError() >= 1.0) accuracy = 0.0;
110  if (accuracy < 0) accuracy = 0.0;
111  if (accuracy > 1) accuracy = 1;
112 
113  if (getHeightVector() != -1.0 && info.getHeightVector() != -1.0) {
114  return Prox(dist + getHeightVector() + info.getHeightVector(),
115  info.getError());
116  }
117  return Prox(dist, accuracy);
118 }
119 
121 {
122  if (!dynamic_cast<const VivaldiCoordsInfo*>(&info)) return false;
123 
124  const VivaldiCoordsInfo& temp = static_cast<const VivaldiCoordsInfo&>(info);
125  if (coordErr > temp.coordErr) {
126  coordErr = temp.coordErr;
127  coordinates = temp.coordinates;
128  heightVector = temp.heightVector;
129 
130  return true;
131  }
132  return false;
133 }
134 
135 VivaldiCoordsInfo::operator Coords() const
136 {
137  Coords temp;
138  for (uint8_t i = 0; i < coordinates.size(); ++i) {
139  temp.push_back(coordinates[i]);
140  }
141  temp.push_back(coordErr);
142  if (heightVector >= 0) temp.push_back(heightVector);
143 
144  return temp;
145 }
146 
147 std::ostream& operator<<(std::ostream& os, const VivaldiCoordsInfo& info)
148 {
149  if (!info.getCoords().size()) throw cRuntimeError("dim = 0");
150 
151  os << "< ";
152  uint8_t i;
153  for (i = 0; i < info.getCoords().size() - 1; ++i) {
154  os << info.getCoords(i) << ", ";
155  }
156  os << info.getCoords(i) << " >";
157  os << ", Err = " << info.getError();
158  if (info.getHeightVector() != -1.0)
159  os << ", HeightVec = " << info.getHeightVector();
160 
161  return os;
162 }
163 
164 SimpleUnderlayCoordsInfo::operator Coords() const
165 {
166  return coordinates;
167 }
168 
169 
171 {
172  if (!dynamic_cast<const SimpleUnderlayCoordsInfo*>(&abstractInfo)) return false;
173 
174  const SimpleUnderlayCoordsInfo& temp = static_cast<const SimpleUnderlayCoordsInfo&>(abstractInfo);
175 
176  coordinates = temp.coordinates;
177 
178  return true;
179 }
180 
182 {
183  if (!dynamic_cast<const SimpleUnderlayCoordsInfo*>(&abstractInfo)) {
184  return Prox::PROX_UNKNOWN;
185  }
186  const SimpleUnderlayCoordsInfo& info =
187  *(static_cast<const SimpleUnderlayCoordsInfo*>(&abstractInfo));
188 
189  double dist = 0.0;
190 
191  for (uint8_t i = 0; i < info.getDimension(); ++i) {
192  dist += pow(getCoords(i) - info.getCoords(i), 2);
193  }
194  dist = sqrt(dist);
195  dist *= 2;
196 
197  return Prox(dist, 0.7); //TODO
198 }
199 
200 
202 {
203  const SimpleCoordsInfo& temp =
204  dynamic_cast<const SimpleCoordsInfo&>(abstractInfo);
205 
206  return Prox(2 * (accessDelay +
207  temp.getAccessDelay() +
208  EuclideanNcsNodeInfo::getDistance(abstractInfo)), 0.7);
209 }
210 
211 
213 {
214  if (!dynamic_cast<const SimpleCoordsInfo*>(&abstractInfo)) return false;
215 
216  const SimpleCoordsInfo& temp =
217  static_cast<const SimpleCoordsInfo&>(abstractInfo);
218 
219  coordinates = temp.coordinates;
220 
221  return true;
222 }
223 
224 
225 SimpleCoordsInfo::operator Coords() const
226 {
227  Coords temp;
228  for (uint8_t i = 0; i < coordinates.size(); ++i) {
229  temp.push_back(coordinates[i]);
230  }
231  temp.push_back(SIMTIME_DBL(accessDelay));
232 
233  return temp;
234 }
235 
236 std::ostream& operator<<(std::ostream& os, const Coords& coords)
237 {
238  uint8_t dim = coords.size();
239  if (dim == 0) return os;
240 
241  os << "< " << coords[0];
242  for (uint8_t i = 1; i < dim; i++) {
243  os << ", " << coords[i];
244  }
245  os << " >";
246  return os;
247 }