User Manual, Developers Guide and API Documentation

MapShadowing.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <RISE/scenario/shadowing/MapShadowing.hpp>
00029 #include <RISE/scenario/scenerymap/SceneryMap.hpp>
00030 #include <RISE/stations/station.hpp>
00031 
00032 #include <WNS/StaticFactoryBroker.hpp>
00033 #include <WNS/pyconfig/View.hpp>
00034 
00035 #include <string>
00036 
00037 using namespace rise::scenario::shadowing;
00038 
00039 STATIC_FACTORY_BROKER_REGISTER(Map, Shadowing, "Map");
00040 
00041 Map::Map(const wns::pyconfig::View&)
00042     : Shadowing()
00043 {
00044 }
00045 
00046 wns::Ratio Map::getShadowing(const antenna::Antenna& source, const antenna::Antenna& target) const
00047 {
00048     const ShadowingMap2D* shadowingMap;
00049     const Interpolation2D* interpolatedMap;
00050     // let's call the station, that has the map, well, umm... base! ;-)
00051     const antenna::Antenna* baseAntenna;
00052     const antenna::Antenna* mobileAntenna;
00053 
00054     if (!source.getStation()->hasPathlossMap()) {
00055     baseAntenna = &source;
00056     mobileAntenna = &target;
00057     }
00058     else {
00059     baseAntenna = &target;
00060     mobileAntenna = &source;
00061     }
00062 
00063     shadowingMap = &baseAntenna->getStation()->getShadowingMap();
00064     interpolatedMap = &baseAntenna->getStation()->getInterpolatedShadowingMap();
00065 
00066     // Calculate the point on the line "source - target" with a distance of 1 from source.
00067     const double dx = baseAntenna->getPosition().getX() - mobileAntenna->getPosition().getX();
00068     const double dy = baseAntenna->getPosition().getY() - mobileAntenna->getPosition().getY();
00069 
00070     const double len = sqrt(dx*dx + dy*dy);
00071 
00072     double x = (mobileAntenna->getPosition().getX() / shadowingMap->getResolution(scenerymap::Dim::X)) + dx/len;
00073     double y = (mobileAntenna->getPosition().getY() / shadowingMap->getResolution(scenerymap::Dim::Y)) + dy/len;
00074 
00075     if (x > shadowingMap->dimSize(scenerymap::Dim::X) - 1) x = shadowingMap->dimSize(scenerymap::Dim::X) - 1;
00076     if (y > shadowingMap->dimSize(scenerymap::Dim::Y) - 1) y = shadowingMap->dimSize(scenerymap::Dim::Y) - 1;
00077 
00078     return wns::Ratio::from_dB((*interpolatedMap)[x][y]);
00079 }

Generated on Fri May 25 03:31:59 2012 for openWNS by  doxygen 1.5.5