![]() |
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 <RISE/antenna/pattern/kernel/Planet.hpp> 00029 00030 #include <fstream> 00031 00032 using namespace rise::antenna::pattern::kernel; 00033 00034 Planet::Planet() 00035 : TwoDimensional() 00036 { 00037 pd_startUp(); 00038 } 00039 00040 Planet::Planet(const std::string type, 00041 const std::string pattern) 00042 : TwoDimensional(type, pattern) 00043 {} 00044 00045 Planet::~Planet() 00046 {} 00047 00048 Kernel* Planet::createPatternKernel(const std::string type, 00049 const std::string pattern) 00050 { 00051 Planet* pk = new Planet(type, pattern); 00052 pk -> readPattern(); 00053 return pk; 00054 } 00055 00056 void Planet::readPattern() 00057 { 00058 MESSAGE_BEGIN(NORMAL, log, m,"Reading new pattern from file: "); 00059 m << pattern << "... "; 00060 MESSAGE_END(); 00061 std::ifstream patternfile; 00062 patternfile.open(pattern.c_str()); 00063 if(patternfile.good() == false) 00064 { 00065 MESSAGE_BEGIN(NORMAL, log, m,"The following file could not be open: "); 00066 m << pattern; 00067 m << ". Check if the file name is correct. Exiting..."; 00068 MESSAGE_END(); 00069 exit(0); 00070 } 00071 std::string tmp_string = ""; 00072 while (tmp_string != "GAIN") 00073 patternfile >> tmp_string; 00074 wns::Ratio r; 00075 patternfile >> r; 00076 pd_gain = r.get_dB(); 00077 00078 unsigned long int i = 0, horSize = 0, vertSize = 0; 00079 double tmp_double = 0; 00080 00081 while (tmp_string != "HORIZONTAL") 00082 patternfile >> tmp_string; 00083 patternfile >> horSize; 00084 pd_azimuthVector = Double64Vector (horSize + 1); 00085 for (i = 0; i < horSize; i++) 00086 { 00087 patternfile >> tmp_double; 00088 patternfile >> tmp_double; 00089 pd_azimuthVector[i] = -tmp_double; 00090 } 00091 pd_azimuthVector[i] = pd_azimuthVector[0]; 00092 00093 while (tmp_string != "VERTICAL") 00094 patternfile >> tmp_string; 00095 patternfile >> vertSize; 00096 pd_elevationVector = Double64Vector (vertSize + 1); 00097 for (i = 0; i < vertSize; i++) 00098 { 00099 patternfile >> tmp_double; 00100 patternfile >> tmp_double; 00101 pd_elevationVector[i] = -tmp_double; 00102 } 00103 pd_elevationVector[i] = pd_elevationVector[0]; 00104 00105 patternfile.close(); 00106 pd_startUp(); 00107 MESSAGE_BEGIN(NORMAL, log, m,"Pattern read."); 00108 MESSAGE_END(); 00109 } 00110 00111 void Planet::pd_startUp() 00112 { 00113 pd_elevationAngleStep = 2 * M_PI / pd_elevationVector.size(); 00114 pd_azimuthAngleStep = 2 * M_PI / pd_azimuthVector.size(); 00115 } 00116 00117 wns::Ratio Planet::getGain(const wns::Direction& direction) 00118 { 00119 unsigned long int azimuth_index = (unsigned long int)(direction.getAzimuth()/pd_azimuthAngleStep); 00120 unsigned long int elevation_index = 0; 00121 double vert_plane_angle = 0; 00122 if (((direction.getAzimuth() >= 0) && (direction.getAzimuth() <= M_PI/2)) || 00123 ((direction.getAzimuth() >= 3*M_PI/2) && (direction.getAzimuth() <= 2*M_PI))) 00124 { 00125 vert_plane_angle = direction.getElevation() + 3*M_PI/2; 00126 if (vert_plane_angle > M_PI + M_PI) 00127 vert_plane_angle -= (M_PI + M_PI); 00128 elevation_index =(unsigned long int)(vert_plane_angle/pd_elevationAngleStep); 00129 } else { 00130 vert_plane_angle = 3*M_PI/2 - direction.getElevation(); 00131 elevation_index =(unsigned long int)(vert_plane_angle/pd_elevationAngleStep); 00132 } 00133 wns::Ratio directivity; 00134 directivity.set_dB(pd_elevationVector.at(elevation_index) + 00135 pd_azimuthVector.at(azimuth_index) + pd_gain); 00136 return directivity; 00137 } 00138 00139
1.5.5