CoordinateSystem.h

Go to the documentation of this file.
00001 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 2
00006 // of the License, or (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00016 //
00017 
00023 #ifndef COORDINATESYSTEM_H_
00024 #define COORDINATESYSTEM_H_
00025 
00026 #include <stdint.h>
00027 #include <vector>
00028 
00029 #include <omnetpp.h>
00030 
00031 class Prox;
00032 class NeighborCache;
00033 class BaseCallMessage;
00034 
00035 
00036 class AbstractNcsNodeInfo
00037 {
00038 public:
00039     virtual ~AbstractNcsNodeInfo() {};
00040     virtual bool isValid() = 0;
00041     virtual Prox getDistance(const AbstractNcsNodeInfo& node) const = 0;
00042     virtual bool update(const AbstractNcsNodeInfo& info) = 0;
00043 
00044     virtual operator std::vector<double>() const = 0;
00045 };
00046 
00047 class EuclideanNcsNodeInfo : public AbstractNcsNodeInfo
00048 {
00049 public:
00050     EuclideanNcsNodeInfo() { coordinates.resize(dim); };
00051     virtual ~EuclideanNcsNodeInfo() { };
00052 
00053     uint8_t getDimension() const { return coordinates.size(); };
00054     static void setDimension(uint8_t dimension) { dim = dimension; };
00055 
00056     double getCoords(uint8_t i) const {
00057         if (i >= coordinates.size()) {
00058             throw cRuntimeError("too high value for dim!");
00059         }
00060         return coordinates[i];
00061     };
00062 
00063     const std::vector<double>& getCoords() const { return coordinates; };
00064 
00065     void setCoords(uint8_t i, double value) {
00066         if (i >= coordinates.size()) {
00067             throw cRuntimeError("coordinates too small");
00068         }
00069         coordinates[i] = value;
00070     };
00071 
00072     Prox getDistance(const AbstractNcsNodeInfo& abstractInfo) const;
00073 
00074 protected:
00075     std::vector<double> coordinates;
00076     static uint8_t dim;
00077 };
00078 
00079 class GnpNpsCoordsInfo : public EuclideanNcsNodeInfo
00080 {
00081 public:
00082     GnpNpsCoordsInfo() { npsLayer = -1; };
00083 
00084     bool isValid() { return npsLayer != -1; };
00085 
00086     int8_t getLayer() const { return npsLayer; };
00087     void setLayer(int8_t layer) { npsLayer = layer; };
00088 
00089     bool update(const AbstractNcsNodeInfo& abstractInfo);
00090 
00091     operator std::vector<double>() const;
00092 
00093 protected:
00094     int8_t npsLayer;
00095 };
00096 
00097 std::ostream& operator<<(std::ostream& os, const GnpNpsCoordsInfo& info);
00098 
00099 
00100 class SimpleCoordsInfo : public EuclideanNcsNodeInfo
00101 {
00102   public:
00103     bool isValid() { return true; };
00104 
00105     Prox getDistance(const AbstractNcsNodeInfo& abstractInfo) const;
00106     bool update(const AbstractNcsNodeInfo& abstractInfo);
00107 
00108     simtime_t getAccessDelay() const { return accessDelay; };
00109     void setAccessDelay(simtime_t delay) { accessDelay = delay; };
00110 
00111     operator std::vector<double>() const;
00112 
00113 protected:
00114     simtime_t accessDelay;
00115 };
00116 
00117 std::ostream& operator<<(std::ostream& os, const SimpleCoordsInfo& info);
00118 
00119 
00120 class VivaldiCoordsInfo : public EuclideanNcsNodeInfo
00121 {
00122 public:
00123     VivaldiCoordsInfo(bool useHeightVector = false) {
00124         coordErr = 1.0;
00125         heightVector = (useHeightVector ? 0 : -1.0);
00126     };
00127 
00128     bool isValid() { return coordErr >= 0.0 && coordErr < 1.0; };
00129 
00130     double getError() const { return coordErr; };
00131     void setError(double err) {
00132         coordErr = ((err > 1.0) ? 1.0 : ((err < 0.0) ? 0.0 : coordErr = err));
00133     };
00134 
00135     double getHeightVector() const { return heightVector; };
00136     void setHeightVector(double height) {
00137         heightVector = ((height > 0.0) ? height : 0.0);
00138     };
00139 
00140     Prox getDistance(const AbstractNcsNodeInfo& node) const;
00141     bool update(const AbstractNcsNodeInfo& info);
00142     operator std::vector<double>() const ;
00143 
00144 protected:
00145     double coordErr;
00146     double heightVector;
00147 };
00148 
00149 std::ostream& operator<<(std::ostream& os, const VivaldiCoordsInfo& info);
00150 
00151 class AbstractNcs {
00152   public:
00153     virtual ~AbstractNcs() { };
00154 
00155     virtual void init(NeighborCache* neighorCache) = 0;
00156 
00157     virtual AbstractNcsNodeInfo* getUnvalidNcsInfo() const = 0;
00158 
00159     virtual Prox getCoordinateBasedProx(const AbstractNcsNodeInfo& node) const = 0;
00160     virtual void processCoordinates(const simtime_t& rtt,
00161                                     const AbstractNcsNodeInfo& nodeInfo) { };
00162 
00163     virtual const AbstractNcsNodeInfo& getOwnNcsInfo() const = 0;
00164     virtual AbstractNcsNodeInfo* createNcsInfo(const std::vector<double>& coords) const = 0;
00165 
00166     virtual void handleTimerEvent(cMessage* msg) { };
00167     virtual bool handleRpcCall(BaseCallMessage* msg) { return false; };
00168 };
00169 
00170 #endif /* COORDINATESYSTEM_H_ */