00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <math.h>
00025 #include <float.h>
00026 #include <string.h>
00027
00028 #include "LocateSensor.hh"
00029
00030
00031 inline void clLocateSensor::Clear ()
00032 {
00033 memset(fpLocMatrix, 0x00, lWidth * lHeight * sizeof(GDT));
00034 }
00035
00036
00037 inline void clLocateSensor::SetValue (long lX, long lY, GDT fValue)
00038 {
00039 if (lX < 0 || lX >= lWidth) return;
00040 if (lY < 0 || lY >= lHeight) return;
00041 fpLocMatrix[lY * lWidth + lX] += fValue;
00042 }
00043
00044
00045 void clLocateSensor::SetDirection (GDT fDirection, GDT fLevel, GDT fFrequency)
00046 {
00047 long lX1;
00048 long lY1;
00049 long lX2 = 0;
00050 long lY2 = 0;
00051 GDT fDistance;
00052 GDT fThisDir;
00053 GDT fAbsCoeff;
00054 GDT fPropLoss;
00055 GDT fNewLevel;
00056
00057 if (!b3D && (fDirection < -fHalfPI || fDirection > fHalfPI))
00058 return;
00059 fDistance = 1;
00060 fAbsCoeff = 0.05 * pow(fFrequency / 1000, 1.4);
00061 do {
00062
00063 fPropLoss = 15 * log10(fDistance) + fAbsCoeff *
00064 fDistance * pow(10, -3);
00065 fNewLevel = fLevel * pow(10, fPropLoss / 20);
00066 fThisDir = fDirection + fAzimuth;
00067 lX1 = DSP.Round(sin(fThisDir) * fDistance) + lPosX;
00068 lY1 = DSP.Round(cos(fThisDir) * fDistance) + lPosY;
00069 SetValue(lX1, lY1, fNewLevel);
00070 if (!b3D)
00071 {
00072 fThisDir = fPI - fDirection + fAzimuth;
00073 lX2 = DSP.Round(sin(fThisDir) * fDistance) + lPosX;
00074 lY2 = DSP.Round(cos(fThisDir) * fDistance) + lPosY;
00075 SetValue(lX2, lY2, fNewLevel);
00076 }
00077 fDistance += 1;
00078 } while ((lX1 >= 0 && lX1 < lWidth && lY1 >= 0 && lY1 < lHeight) ||
00079 (lX2 >= 0 && lX2 < lWidth && lY2 >= 0 && lY2 < lHeight));
00080 }
00081
00082
00083 clLocateSensor::clLocateSensor ()
00084 {
00085 bInitialized = false;
00086 fPI = acos(-1.0);
00087 fHalfPI = acos(-1.0) / 2.0;
00088 }
00089
00090
00091 clLocateSensor::~clLocateSensor ()
00092 {
00093 if (bInitialized) Uninitialize();
00094 }
00095
00096
00097 bool clLocateSensor::Initialize (long lW, long lH, long lX, long lY,
00098 GDT fA, bool bTD)
00099 {
00100 lWidth = lW;
00101 lHeight = lH;
00102 lPosX = lX;
00103 lPosY = lY;
00104 fAzimuth = -fA;
00105 b3D = bTD;
00106 try
00107 {
00108 fpLocMatrix = (GDT *) LocMatrix.Size(lWidth * lHeight * sizeof(GDT));
00109 }
00110 catch (...)
00111 {
00112 return false;
00113 }
00114 Clear();
00115 return true;
00116 }
00117
00118
00119 void clLocateSensor::Uninitialize ()
00120 {
00121
00122 }
00123
00124
00125 void clLocateSensor::SetDirectionValues (const GDT *fpLevelValues,
00126 const GDT *fpDirectionValues, long lValueCount,
00127 long lMinBin, long lMaxBin, GDT fFreqResolution)
00128 {
00129 long lValueCntr;
00130
00131 Clear();
00132 for (lValueCntr = lMinBin; lValueCntr < lMaxBin; lValueCntr++)
00133 {
00134
00135
00136
00137 SetDirection(fpDirectionValues[lValueCntr], fpLevelValues[lValueCntr],
00138 (GDT) lValueCntr * fFreqResolution);
00139 }
00140 }
00141