NMPB08 Shared Libraries
PathStructures.h
Go to the documentation of this file.
00001 
00008 #ifndef _NMPB08_PATHSTRUCT_INCLUDED_
00009 #define _NMPB08_PATHSTRUCT_INCLUDED_
00010 
00011 #include "pathdefNMPB.h"
00012 #include <vector>
00013 #include "math.h"
00014 #include "stdio.h"
00015 using namespace std;
00016 
00017 // on Unix-like systems there is no way_ to hide local classes ant to prevent them from 
00018 // being replaced by other classes with similar names in other libraries. The use of 
00019 // unusual names may help preventing name clashes.
00020 
00021 #ifndef _WIN32
00022 #define  ProfilePointNMPB   _Local_PROPAN8_ProfilePointNMPB_
00023 #define  PropagationPath        _Local_PROPAN8_PropagationPath_
00024 #endif
00025 
00026 #define NULE 0 
00027 
00031 #define cSound ((double) 340) 
00032 
00035 #define PI ((double) 3.14159265358979323)
00036 
00037 // Computes the distance between two 2D points
00038 double distance2D(Position2D const* position1, Position2D const* position2);
00039 
00040 // Computes the distance between two 3D points
00041 double distance3D(Position3D const* position1, Position3D const* position2);
00042 
00043 // Computes the ground distance between 2 positions
00044 double GroundDistance(Position3D const* position1, Position3D const* position2);
00045 
00049 struct ProfilePointNMPB
00050 {
00054         Position3D* position3D;  
00058         Position2D* position2D; 
00062         double          impedance;
00066         bool            isDiff ;        
00070         double          height ;                
00074         double          h_ray;  
00078         ExtensionNMPB* ext ;
00079 
00083         ProfilePointNMPB()
00084         {
00085                 ext = new ExtensionNMPB;
00086                 ext->type = ETNone_NMPB;
00087                 ext->height = 0;
00088                 ext->alphaArray = NULE;
00089                 ext->cosTheta = 1;
00090 
00091                 isDiff = 0;
00092                 impedance = 0;
00093                 h_ray = 0;
00094                 height = 0 ;
00095                 position3D = new Position3D;
00096                 position3D->x = 0;
00097                 position3D->y = 0;
00098                 position3D->z = 0;
00099                 position2D = new Position2D;
00100                 position2D->d = 0;
00101                 position2D->z = 0;
00102         } ;
00103 
00107         ~ProfilePointNMPB(void)
00108         {
00109                 delete ext;
00110                 delete position2D;
00111                 delete position3D;
00112         }
00113 
00119         void Copy(ProfilePointNMPB const* pointToCopy)
00120         {
00121                 impedance = pointToCopy->impedance;
00122                 isDiff = pointToCopy->isDiff;
00123                 height = pointToCopy->height;
00124                 h_ray = pointToCopy->h_ray;             
00125                 ext = pointToCopy->ext;
00126                 position3D->x = pointToCopy->position3D->x;
00127                 position3D->y = pointToCopy->position3D->y;
00128                 position3D->z = pointToCopy->position3D->z;
00129                 position2D->d = pointToCopy->position2D->d;
00130                 position2D->z = pointToCopy->position2D->z;
00131         }
00132 
00138         Position2D* position2D_withHeight(void)
00139         {
00140                 Position2D* posWithHeight = new Position2D;
00141                 posWithHeight->d = position2D->d;
00142                 posWithHeight->z = position2D->z + height;
00143                 return posWithHeight;
00144         }
00145 
00151         Position3D* position3D_withHeight(void)
00152         {
00153                 Position3D* posWithHeight = new Position3D;
00154                 posWithHeight->x = position3D->x;
00155                 posWithHeight->y = position3D->y;
00156                 posWithHeight->z = position3D->z + height;
00157                 return posWithHeight;
00158         }
00159 } ;
00160 
00164 struct PropagationPath
00165 {
00169         vector<ProfilePointNMPB*> pathPoints;
00173         double distSR;
00177         vector<double> frequencies;
00181         double* favorableAttenuations; 
00185         double* homogeneousAttenuations; 
00186 
00190         PropagationPath(void)
00191         : pathPoints()
00192         , frequencies()
00193         {
00194                 distSR = 0;
00195                 _selectedOptions = 0;
00196                 favorableAttenuations = 0 ; 
00197                 homogeneousAttenuations = 0 ;
00198         } ;
00199 
00203         ~PropagationPath(void)
00204         {
00205                 while(!pathPoints.empty()){
00206                         ProfilePointNMPB* pathPoint = pathPoints.back();
00207                         pathPoints.pop_back();
00208                         delete pathPoint;
00209                 }
00210                 delete [] favorableAttenuations;
00211                 delete [] homogeneousAttenuations;
00212         }
00213 
00221         void ExtendPath (Position3D const* point3D, double g)
00222         {
00223                 ProfilePointNMPB* pathPoint = new ProfilePointNMPB;
00224                 pathPoint->position3D->x = point3D->x;
00225                 pathPoint->position3D->y = point3D->y;
00226                 pathPoint->position3D->z = point3D->z;
00227                 pathPoint->impedance = g;
00228                 ExtensionNMPB* ext = new ExtensionNMPB;
00229                 ext->height = 0;
00230                 ext->alphaArray = NULE;
00231                 ext->type = ETNone_NMPB ;
00232                 ext->cosTheta = 1;
00233                 pathPoint->ext = ext;
00234 
00235                 pathPoints.push_back(pathPoint);
00236         }
00237 
00247         void ExtendPathExt (Position3D const* point3D, double g,  ExtensionNMPB const* ext)
00248         {
00249                 if(ext != NULE && ext->type == ETScreen_NMPB)
00250                 {
00251                         // Screen to add to path : 3 points :
00252                         ProfilePointNMPB* pathPoint1 = new ProfilePointNMPB;
00253                         pathPoint1->position3D->x = point3D->x;
00254                         pathPoint1->position3D->y = point3D->y;
00255                         pathPoint1->position3D->z = point3D->z;
00256                         pathPoint1->impedance = g;
00257                         pathPoints.push_back(pathPoint1);
00258 
00259                         ProfilePointNMPB* pathPoint2 = new ProfilePointNMPB;
00260                         pathPoint2->position3D->x = point3D->x;
00261                         pathPoint2->position3D->y = point3D->y;
00262                         pathPoint2->position3D->z = point3D->z + ext->height;
00263                         pathPoint2->impedance = g;
00264                         pathPoints.push_back(pathPoint2);
00265 
00266                         ProfilePointNMPB* pathPoint3 = new ProfilePointNMPB;
00267                         pathPoint3->position3D->x = point3D->x + 0.001;
00268                         pathPoint3->position3D->y = point3D->y;
00269                         pathPoint3->position3D->z = point3D->z;
00270                         pathPoint3->impedance = g;
00271                         pathPoints.push_back(pathPoint3);
00272                 }
00273                 else
00274                 {
00275                         ProfilePointNMPB* pathPoint = new ProfilePointNMPB;
00276                         pathPoint->position3D->x = point3D->x;
00277                         pathPoint->position3D->y = point3D->y;
00278                         pathPoint->position3D->z = point3D->z;
00279                         pathPoint->impedance = g;
00280                         if(ext == NULE)
00281                         {
00282                                 pathPoint->ext = NULE;
00283                         }
00284                         else
00285                         {
00286                                 pathPoint->ext->type = ext->type;
00287                                 pathPoint->ext->height = ext->height;
00288                                 pathPoint->ext->alphaArray = ext->alphaArray;
00289                                 pathPoint->ext->cosTheta = ext->cosTheta;
00290                                 if(ext->type == ETSideDiffraction_NMPB)
00291                                 {
00292                                         // height used in propagation path for side diffractions but not for reflections (in this case, it's only used for retrodiffraction)
00293                                         pathPoint->height = ext->height; 
00294                                 }
00295                         }
00296 
00297                         pathPoints.push_back(pathPoint);
00298                 }
00299         }
00300 
00310         bool SetSourceHeight (double h) 
00311         {
00312                 if (!pathPoints.empty())
00313                 {
00314                         pathPoints[0]->height = h;
00315                         return true;
00316                 }
00317                 else
00318                 {
00319                         printf (".ERROR: path empty \n") ;
00320                         throw new int( ERRNoPoint );
00321                 }
00322                 
00323                 return false;
00324         }
00325 
00335         bool SetReceiverHeight (double h)
00336         {
00337                 if (!pathPoints.empty())
00338                 {
00339                         pathPoints[pathPoints.size()-1]->height = h;
00340                         return true;
00341                 }
00342                 else
00343                 {
00344                         printf (".ERROR: path empty \n") ;
00345                         throw new int( ERRNoPoint );
00346                 }
00347 
00348                 return false;
00349         }
00350 
00356         ProfilePointNMPB* GetSource()
00357         {
00358                 if (!pathPoints.empty())
00359                 {
00360                         return pathPoints[0];
00361                 }
00362 
00363                 return 0;
00364         }
00365 
00371         ProfilePointNMPB* GetReceiver()
00372         {
00373                 if (!pathPoints.empty())
00374                 {
00375                         return pathPoints[pathPoints.size()-1];
00376                 }
00377 
00378                 return 0;
00379         }
00380 
00388         void SetFrequencies (int nbFreq, double const* freq)
00389         {
00390                 frequencies.clear();
00391                 if (nbFreq > 0)
00392                 {
00393                         for (int i = 0 ; i < nbFreq ; i++)
00394                         {
00395                                 frequencies.push_back (freq[i]);
00396                         }
00397                 }
00398         }
00399 
00405         int GetNbFrequencies ()
00406         {
00407                 return (int) frequencies.size() ;
00408         }
00409 
00415         double const* GetFrequencies ()
00416         {
00417                 int nbFreq = (int) frequencies.size();
00418                 if (nbFreq > 0)
00419                 {
00420                         double const* freqArr = &frequencies[0];
00421                         return freqArr;
00422                 }
00423 
00424                 return 0;
00425         }
00426 
00434         int GetFrequencyPosition(double freq)
00435         {
00436                 int fPos = -1;
00437                 int nbFreq = (int) frequencies.size();
00438                 if (nbFreq > 0)
00439                 {
00440                         for(int i = 0 ; i < nbFreq ; i++)
00441                         {
00442                                 if (frequencies[i] == freq) return i;
00443                         }
00444                 }
00445 
00446                 return fPos;
00447         }
00448 
00456         void SetOption(Option option, bool on_off)
00457         {
00458                 if(on_off)
00459                 {
00460                         _selectedOptions |= option; 
00461                 }
00462                 else
00463                 {
00464                         _selectedOptions &= ~option; 
00465                 }
00466         }
00467 
00475         bool GetOption(Option option)
00476         {
00477                 return (option == (option & _selectedOptions));
00478         }
00479 
00483         void ClearPath()
00484         {
00485                 while(!pathPoints.empty())
00486                 {
00487                         ProfilePointNMPB* pathPoint = pathPoints.back();
00488                         pathPoints.pop_back();
00489                         delete pathPoint;
00490                 }
00491                 distSR = 0;
00492         }
00493 
00494         private:
00498                 int _selectedOptions;
00499 };
00500 
00501 // Fills the TerrainItem Position2D
00502 void FillPlanePosition(ProfilePointNMPB* terrain, ProfilePointNMPB const* source, double cumDistance);
00503 
00504 
00505 #endif
00506 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines