OverSim
CoordinateSystem.h
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 #ifndef COORDINATESYSTEM_H_
24 #define COORDINATESYSTEM_H_
25 
26 #include <stdint.h>
27 #include <vector>
28 
29 #include <omnetpp.h>
30 
31 class Prox;
32 class NeighborCache;
34 
35 
36 
37 typedef std::vector<double> Coords;
38 typedef std::vector<Coords> CoordsVec;
39 std::ostream& operator<<(std::ostream& os, const Coords& coords);
40 
41 
43 {
44 public:
45  virtual ~AbstractNcsNodeInfo() {};
46  virtual bool isValid() = 0;
47  virtual Prox getDistance(const AbstractNcsNodeInfo& node) const = 0;
48  virtual bool update(const AbstractNcsNodeInfo& info) = 0;
49 
50  virtual const Coords& getCoords() const = 0;
51 
52  virtual operator Coords() const = 0;
53 };
54 
56 {
57 public:
59  virtual ~EuclideanNcsNodeInfo() { };
60 
61  uint8_t getDimension() const { return coordinates.size(); };
62  static void setDimension(uint8_t dimension) { dim = dimension; };
63 
64  double getCoords(uint8_t i) const {
65  if (i >= coordinates.size()) {
66  throw cRuntimeError("too high value for dim!");
67  }
68  return coordinates[i];
69  };
70 
71  const Coords& getCoords() const { return coordinates; };
72 
73  void setCoords(uint8_t i, double value) {
74  if (i >= coordinates.size()) {
75  throw cRuntimeError("coordinates too small");
76  }
77  coordinates[i] = value;
78  };
79 
80  Prox getDistance(const AbstractNcsNodeInfo& abstractInfo) const;
81 
82 protected:
84  static uint8_t dim;
85 };
86 
88 {
89 public:
91 
92  bool isValid() { return npsLayer != -1; };
93 
94  int8_t getLayer() const { return npsLayer; };
95  void setLayer(int8_t layer) { npsLayer = layer; };
96 
97  bool update(const AbstractNcsNodeInfo& abstractInfo);
98 
99  operator Coords() const;
100 
101 protected:
102  int8_t npsLayer;
103 };
104 
105 std::ostream& operator<<(std::ostream& os, const GnpNpsCoordsInfo& info);
106 
107 
109 {
110 public:
111  //SimpleUnderlayCoordsInfo() { };
112 
113  operator Coords() const;
114 
115  bool isValid() { return true; };
116 
117  Prox getDistance(const AbstractNcsNodeInfo& abstractInfo) const;
118  bool update(const AbstractNcsNodeInfo& abstractInfo);
119 };
120 
121 
123 {
124  public:
125  bool isValid() { return true; };
126 
127  Prox getDistance(const AbstractNcsNodeInfo& abstractInfo) const;
128  bool update(const AbstractNcsNodeInfo& abstractInfo);
129 
130  simtime_t getAccessDelay() const { return accessDelay; };
131  void setAccessDelay(simtime_t delay) { accessDelay = delay; };
132 
133  operator Coords() const;
134 
135 protected:
136  simtime_t accessDelay;
137 };
138 
139 std::ostream& operator<<(std::ostream& os, const SimpleCoordsInfo& info);
140 
141 
143 {
144 public:
145  VivaldiCoordsInfo(bool useHeightVector = false) {
146  coordErr = 1.0;
147  heightVector = (useHeightVector ? 0 : -1.0);
148  };
149 
150  bool isValid() { return coordErr >= 0.0 && coordErr < 1.0; };
151 
152  double getError() const { return coordErr; };
153  void setError(double err) {
154  if (err > 1.0) {
155  coordErr = 1.0;
156  } else if (err < 0.0) {
157  coordErr = 0.0;
158  } else {
159  coordErr = err;
160  }
161  //coordErr = ((err > 1.0) ? 1.0 : ((err < 0.0) ? 0.0 : coordErr = err));
162  };
163 
164  double getHeightVector() const { return heightVector; };
165  void setHeightVector(double height) {
166  heightVector = ((height > 0.0) ? height : 0.0);
167  };
168 
169  Prox getDistance(const AbstractNcsNodeInfo& node) const;
170  bool update(const AbstractNcsNodeInfo& info);
171  operator Coords() const ;
172 
173 protected:
174  double coordErr;
175  double heightVector;
176 };
177 
178 std::ostream& operator<<(std::ostream& os, const VivaldiCoordsInfo& info);
179 
180 class AbstractNcs {
181  public:
182  virtual ~AbstractNcs() { };
183 
184  virtual void init(NeighborCache* neighorCache) = 0;
185  virtual bool isReady() {return true; };
186 
187  virtual AbstractNcsNodeInfo* getUnvalidNcsInfo() const = 0;
188 
189  virtual Prox getCoordinateBasedProx(const AbstractNcsNodeInfo& node) const = 0;
190  virtual void processCoordinates(const simtime_t& rtt,
191  const AbstractNcsNodeInfo& nodeInfo) { };
192 
193  virtual const AbstractNcsNodeInfo& getOwnNcsInfo() const = 0;
194  virtual AbstractNcsNodeInfo* createNcsInfo(const Coords& coords) const = 0;
195 
196  virtual void handleTimerEvent(cMessage* msg) { };
197  virtual bool handleRpcCall(BaseCallMessage* msg) { return false; };
198 };
199 
200 #endif /* COORDINATESYSTEM_H_ */