Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "LdmrsScanpointCoordinateApp.hpp"
00015 #include "../tools/errorhandler.hpp"
00016 #include "../tools/toolbox.hpp"
00017 #include "../datatypes/Scan.hpp"
00018 #include "../datatypes/Object.hpp"
00019 #include "../datatypes/Msg.hpp"
00020 #include "../datatypes/Measurement.hpp"
00021 #include "../datatypes/Fields.hpp"
00022 #include "../datatypes/EvalCases.hpp"
00023 #include "../datatypes/EvalCaseResults.hpp"
00024
00025 namespace application
00026 {
00027
00028
00029
00030
00031 LdmrsScanpointCoordinateApp::LdmrsScanpointCoordinateApp(Manager* manager)
00032 {
00033
00034 m_beVerbose = false;
00035
00036
00037
00038 m_numScansToCount = 20;
00039
00040
00041
00042
00043
00044 m_wantedHorzAngle = 0.0 * deg2rad;
00045
00046
00047 initCycle();
00048 m_isFourLayerScanner = true;
00049
00050 printInfoMessage("LdmrsScanpointCoordinateApp constructor done.", m_beVerbose);
00051 }
00052
00053
00054
00055
00056 LdmrsScanpointCoordinateApp::~LdmrsScanpointCoordinateApp()
00057 {
00058 printInfoMessage("LdmrsScanpointCoordinateApp says Goodbye!", m_beVerbose);
00059 }
00060
00061
00062
00063
00064 void LdmrsScanpointCoordinateApp::initCycle()
00065 {
00066 m_scanCounter = 0;
00067 for (UINT8 i = 0; i<8; i++)
00068 {
00069 m_numPoints[i] = 0;
00070 m_meanDist[i] = 0.0;
00071 m_meanXyz[i] = Point3D(0.0, 0.0, 0.0);
00072 }
00073 }
00074
00075
00076
00077
00078
00079 void LdmrsScanpointCoordinateApp::setData(BasicData& data)
00080 {
00081
00082
00083
00084
00085
00086 std::string datatypeStr;
00087 std::string sourceIdStr;
00088
00089 if (data.getDatatype() == Datatype_Scan)
00090 {
00091 Scan* scan = dynamic_cast<Scan*>(&data);
00092
00093
00094 processScan(scan);
00095 m_scanCounter++;
00096
00097 if (m_scanCounter >= m_numScansToCount)
00098 {
00099
00100 calcAndShowStatistics();
00101
00102
00103 initCycle();
00104 }
00105 }
00106
00107 printInfoMessage("LdmrsScanpointCoordinateApp::setData(): Done.", m_beVerbose);
00108 }
00109
00110
00111
00112
00113 void LdmrsScanpointCoordinateApp::calcAndShowStatistics()
00114 {
00115
00116 for (UINT8 layer = 0; layer < 8; layer++)
00117 {
00118 if (m_numPoints[layer] > 1)
00119 {
00120 m_meanXyz[layer] /= static_cast<double>(m_numPoints[layer]);
00121 m_meanDist[layer] /= static_cast<double>(m_numPoints[layer]);
00122 }
00123 }
00124
00125
00126
00127 printInfoMessage(" ", true);
00128 printInfoMessage("Statistics for " + toString(m_numScansToCount) + " scans at angle " +
00129 toString(m_wantedHorzAngle * rad2deg, 1) + " degrees.", true);
00130
00131
00132 INT16 startLayer = 3;
00133 if (m_isFourLayerScanner == false)
00134 {
00135
00136 startLayer = 7;
00137 }
00138
00139 for (INT16 layer = startLayer; layer >= 0; layer -= 1)
00140 {
00141 printInfoMessage("Layer " + toString(layer + 1) + ": " + toString(m_numPoints[layer]) + " pts;" +
00142 " x=" + toString(m_meanXyz[layer].getX(), 2) + " m," +
00143 " y=" + toString(m_meanXyz[layer].getY(), 2) + " m," +
00144 " z=" + toString(m_meanXyz[layer].getZ(), 2) + " m," +
00145 "; dist=" + toString(m_meanDist[layer], 2) + " m.", true);
00146 }
00147 printInfoMessage(" ", true);
00148 }
00149
00150
00151
00152
00153 bool LdmrsScanpointCoordinateApp::isFourLayerScanner(Scan* scan)
00154 {
00155 printInfoMessage("LdmrsScanpointCoordinateApp::isFourLayerScanner: Beam tilt=" + toString(fabs(scan->getScannerInfos().at(0).getBeamTilt() * rad2deg), 1) + " degrees.", m_beVerbose);
00156
00157
00158 if (fabs(scan->getScannerInfos().at(0).getBeamTilt()) < (0.2 * deg2rad))
00159 {
00160
00161 return true;
00162 }
00163
00164 return false;
00165 }
00166
00167
00168
00169
00170 void LdmrsScanpointCoordinateApp::processScan(Scan* scan)
00171 {
00172 ScanPoint point;
00173 bool success;
00174 UINT8 layerOffset = 0;
00175
00176
00177 if (isFourLayerScanner(scan) == true)
00178 {
00179
00180 m_isFourLayerScanner = true;
00181 layerOffset = 0;
00182 }
00183 else
00184 {
00185
00186 m_isFourLayerScanner = false;
00187
00188
00189 if (scan->getScannerInfos().at(0).isRearMirrorSide() == true)
00190 {
00191
00192 layerOffset = 4;
00193 }
00194 else
00195 {
00196
00197 layerOffset = 0;
00198 }
00199 }
00200
00201
00202
00203 for (UINT8 layer = 0; layer < 4; layer++)
00204 {
00205 success = getClosestScanpoint(layer, m_wantedHorzAngle, scan, &point);
00206 if (success == true)
00207 {
00208
00209
00210 }
00211 else
00212 {
00213 printInfoMessage("LdmrsScanpointCoordinateApp::processScan: No point found for hAngle " + toString(m_wantedHorzAngle * rad2deg, 1) +
00214 " degrees in layer " + toString(layer) + ".", true);
00215 }
00216
00217
00218 m_numPoints[layer + layerOffset]++;
00219 m_meanXyz[layer + layerOffset] += point.toPoint3D();
00220 m_meanDist[layer + layerOffset] += point.getDist();
00221 }
00222 }
00223
00224
00225
00226
00227
00228
00229 bool LdmrsScanpointCoordinateApp::getClosestScanpoint(const UINT8 layer, const double horzAngle, const Scan* scan, ScanPoint* point)
00230 {
00231 UINT32 i;
00232 ScanPoint bestPoint;
00233 ScanPoint currentPoint;
00234 bool success;
00235
00236
00237 bestPoint.setPolar(1000, 90 * deg2rad, 90 * deg2rad);
00238
00239
00240 for (i=0; i<scan->getNumPoints(); i++)
00241 {
00242 currentPoint = scan->at(i);
00243 if (currentPoint.getLayer() == layer)
00244 {
00245
00246
00247 if (fabs(currentPoint.getHAngle() - horzAngle) < fabs(bestPoint.getHAngle() - horzAngle))
00248 {
00249 bestPoint = currentPoint;
00250
00251 }
00252 }
00253 }
00254
00255
00256 if (fabs(bestPoint.getHAngle() - horzAngle) < (2.0 * deg2rad))
00257 {
00258
00259 *point = bestPoint;
00260 success = true;
00261 }
00262 else
00263 {
00264
00265 success = false;
00266 }
00267
00268 return success;
00269 }
00270
00271 }