CoordinateSystem.cc

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 #include <ProxNodeHandle.h>
00024 
00025 #include <CoordinateSystem.h>
00026 
00027 
00028 uint8_t EuclideanNcsNodeInfo::dim;
00029 
00030 Prox GnpNpsCoordsInfo::getDistance(const AbstractNcsNodeInfo& abstractInfo) const
00031 {
00032     if (!dynamic_cast<const GnpNpsCoordsInfo*>(&abstractInfo)) {
00033         return Prox::PROX_UNKNOWN;
00034     }
00035     const GnpNpsCoordsInfo& info =
00036         *(static_cast<const GnpNpsCoordsInfo*>(&abstractInfo));
00037 
00038     double dist = 0.0;
00039 
00040     for (uint8_t i = 0; i < info.getDimension(); ++i) {
00041         dist += pow(getCoords(i) - info.getCoords(i), 2);
00042     }
00043     dist = sqrt(dist);
00044 
00045     return Prox(dist, 0.7); //TODO
00046 }
00047 
00048 bool GnpNpsCoordsInfo::update(const AbstractNcsNodeInfo& abstractInfo)
00049 {
00050     if (!dynamic_cast<const GnpNpsCoordsInfo*>(&abstractInfo)) return false;
00051 
00052     const GnpNpsCoordsInfo& temp =
00053         static_cast<const GnpNpsCoordsInfo&>(abstractInfo);
00054 
00055     coordinates = temp.coordinates;
00056     npsLayer = temp.npsLayer;
00057 
00058     return true;
00059 }
00060 
00061 GnpNpsCoordsInfo::operator std::vector<double>() const {
00062     std::vector<double> temp;
00063     for (uint8_t i = 0; i < coordinates.size(); ++i) {
00064         temp.push_back(coordinates[i]);
00065     }
00066     temp.push_back(npsLayer);
00067 
00068     return temp;
00069 }
00070 
00071 std::ostream& operator<<(std::ostream& os, const GnpNpsCoordsInfo& info)
00072 {
00073     if (!info.getCoords().size()) throw cRuntimeError("dim = 0");
00074 
00075     os << "< ";
00076     uint8_t i;
00077     for (i = 0; i < info.getCoords().size() - 1; ++i) {
00078         os << info.getCoords(i) << ", ";
00079     }
00080     os << info.getCoords(i) << " >";
00081     if (info.getLayer() != -1)
00082         os << ", NPS-Layer = " << (int)info.getLayer();
00083 
00084     return os;
00085 }
00086 
00087 Prox VivaldiCoordsInfo::getDistance(const AbstractNcsNodeInfo& abstractInfo) const
00088 {
00089     if (!dynamic_cast<const VivaldiCoordsInfo*>(&abstractInfo)) {
00090             return Prox::PROX_UNKNOWN;
00091     }
00092     const VivaldiCoordsInfo& info =
00093         *(static_cast<const VivaldiCoordsInfo*>(&abstractInfo));
00094 
00095     double dist = 0.0, accuracy = 0.0;
00096 
00097     for (uint8_t i = 0; i < info.getDimension(); ++i) {
00098         dist += pow(getCoords(i) - info.getCoords(i), 2);
00099     }
00100     dist = sqrt(dist);
00101 
00102     accuracy = 1 - ((info.getError() + getError()) / 2);
00103     if (info.getError() >= 1.0 || getError() >= 1.0) accuracy = 0.0;
00104     if (accuracy < 0) accuracy = 0.0;
00105     if (accuracy > 1) accuracy = 1;
00106 
00107     if (getHeightVector() != -1.0 && info.getHeightVector() != -1.0) {
00108         return Prox(dist + getHeightVector() + info.getHeightVector(),
00109                     info.getError());
00110     }
00111     return Prox(dist, accuracy);
00112 }
00113 
00114 bool VivaldiCoordsInfo::update(const AbstractNcsNodeInfo& info)
00115 {
00116     if (!dynamic_cast<const VivaldiCoordsInfo*>(&info)) return false;
00117 
00118     const VivaldiCoordsInfo& temp = static_cast<const VivaldiCoordsInfo&>(info);
00119     if (coordErr > temp.coordErr) {
00120         coordErr = temp.coordErr;
00121         coordinates = temp.coordinates;
00122         heightVector = temp.heightVector;
00123 
00124         return true;
00125     }
00126     return false;
00127 }
00128 
00129 VivaldiCoordsInfo::operator std::vector<double>() const {
00130     std::vector<double> temp;
00131     for (uint8_t i = 0; i < coordinates.size(); ++i) {
00132         temp.push_back(coordinates[i]);
00133     }
00134     temp.push_back(coordErr);
00135     if (heightVector >= 0) temp.push_back(heightVector);
00136 
00137     return temp;
00138 }
00139 
00140 std::ostream& operator<<(std::ostream& os, const VivaldiCoordsInfo& info)
00141 {
00142     if (!info.getCoords().size()) throw cRuntimeError("dim = 0");
00143 
00144     os << "< ";
00145     uint8_t i;
00146     for (i = 0; i < info.getCoords().size() - 1; ++i) {
00147         os << info.getCoords(i) << ", ";
00148     }
00149     os << info.getCoords(i) << " >";
00150     os << ", Err = " << info.getError();
00151     if (info.getHeightVector() != -1.0)
00152         os << ", HeightVec = " << info.getHeightVector();
00153 
00154     return os;
00155 }
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3