![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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 <fstream> 00029 #include <cassert> 00030 00031 #include <RISE/scenario/sceneryfile/SC.hpp> 00032 #include <RISE/scenario/Scenario.hpp> 00033 #include <RISE/scenario/scenerymap/SceneryMap.hpp> 00034 00035 using namespace rise::scenario::sceneryfile; 00036 00037 SC::SC() : 00038 SceneryFile(), 00039 initialized(false), 00040 morphologyMap(), 00041 pathlossMaps(), 00042 shadowingMap() 00043 { 00044 } 00045 00046 #ifndef WNS_DEBUG 00047 SC::SC(const std::string filename, const scenario::Scenario& scenario) : 00048 #else 00049 SC::SC(const std::string filename, const scenario::Scenario& /*scenario*/) : 00050 #endif 00051 SceneryFile(), 00052 initialized(false), 00053 SCfile(filename.c_str()), 00054 morphologyMap(), 00055 pathlossMaps(), 00056 shadowingMap() 00057 { 00058 std::ifstream SCfile(filename.c_str()); 00059 00060 if (!SCfile.is_open()) throw wns::Exception(("SC: Could not open " + filename).c_str()); 00061 00062 // check if we really have a SC file 00063 char fileMagic[20]; 00064 long int fileVersion = 0; 00065 00066 SCfile.getline(fileMagic, 20); 00067 if (std::string(fileMagic) == "SceneryMap,") fileVersion = 1; 00068 if (std::string(fileMagic) == "SceneryMap2") fileVersion = 2; 00069 if (std::string(fileMagic) == "SceneryMap3") fileVersion = 3; 00070 00071 if (fileVersion == 0) 00072 throw wns::Exception(("SC: " + filename + " not a SC map file").c_str()); 00073 00074 // read in x and y size 00075 long int xSize, ySize; 00076 if (fileVersion < 3) 00077 { 00078 SCfile >> xSize; 00079 ySize = xSize; 00080 } 00081 00082 if (fileVersion >= 3) 00083 { 00084 SCfile >> xSize >> ySize; 00085 } 00086 00087 if ((xSize <= 0) || (ySize <= 0)) 00088 throw wns::Exception("SC: illegal scenario size"); 00089 00090 // read in sqrt of number of shadowing tiles per pathloss/morphology tile 00091 unsigned long int shadowingSize; 00092 SCfile >> shadowingSize; 00093 00094 // read in number of base stations 00095 long int maxBS; 00096 SCfile >> maxBS; 00097 00098 if (maxBS < 1) 00099 throw wns::Exception("SC: too few base stations"); 00100 00101 // read in resolution 00102 unsigned long int resolution; 00103 00104 if (fileVersion >=2) 00105 { 00106 SCfile >> resolution; 00107 } 00108 else 00109 { 00110 resolution = 10; 00111 } 00112 00113 // create maps 00114 scenerymap::resolution resolutions[2] = {resolution, resolution}; 00115 std::size_t sizes[2] = {xSize, ySize}; 00116 scenerymap::resolution shadowingResolutions[2] = {resolution / shadowingSize, resolution / shadowingSize}; 00117 std::size_t shadowingSizes[2] = {xSize * shadowingSize, ySize * shadowingSize}; 00118 00119 morphologyMap = scenerymap::MorphologyMap2D(sizes, resolutions); 00120 pathlossMaps = scenerymap::PathlossMaps2D(maxBS, scenerymap::PathlossMap2D(sizes, resolutions)); 00121 shadowingMap = scenerymap::ShadowingMap2D(shadowingSizes, shadowingResolutions); 00122 00123 // fill maps with values 00124 char aChar; 00125 SCfile.get(aChar); 00126 for (long int y = 0; y < ySize; ++y) 00127 { 00128 for (long int x = 0; x < xSize; ++x) 00129 { 00130 // morphology 00131 SCfile.get(aChar); 00132 morphologyMap[x][y] = (unsigned char)aChar; 00133 00134 // shadowing 00135 for (unsigned long int sy = 0; sy < shadowingSize; ++sy) 00136 { 00137 for (unsigned long int sx = 0; sx < shadowingSize; ++sx) 00138 { 00139 SCfile.get(aChar); 00140 shadowingMap[x*shadowingSize + sx][y*shadowingSize + sy] = aChar; 00141 } 00142 } 00143 00144 // pathloss 00145 for (long int bs = 0; bs < maxBS; ++bs) 00146 { 00147 SCfile.get(aChar); 00148 pathlossMaps[bs][x][y] = (unsigned char)aChar; 00149 } 00150 00151 } 00152 } 00153 00154 initialized = true; 00155 } 00156 00157
1.5.5