00001
00002
00003
00004
00005 #include "Object.hpp"
00006 #include "../tools/errorhandler.hpp"
00007 #include "../tools/MathToolbox.hpp"
00008
00009 namespace datatypes
00010 {
00011
00012
00013 Object::Object()
00014 : m_objectId(0)
00015 , m_flags(0)
00016 , m_objectAge(0)
00017 , m_hiddenStatusAge(0)
00018 , m_timestamp()
00019 , m_classification(Object::Unclassified)
00020 , m_classificationAge(0)
00021 , m_classificationQuality(0.0f)
00022 , m_centerPoint(Point2D(0, 0))
00023 , m_centerPointSigma(Point2D(0, 0))
00024 , m_courseAngle(0.0f)
00025 , m_courseAngleSigma(0.0f)
00026 , m_relativeVelocity(Point2D(0, 0))
00027 , m_relativeVelocitySigma(Point2D(0, 0))
00028 , m_absoluteVelocity(Point2D(0, 0))
00029 , m_absoluteVelocitySigma(Point2D(0, 0))
00030 , m_objectBox(Point2D(0, 0))
00031 , m_objectBoxSigma(Point2D(0, 0))
00032 , m_boundingBoxCenter(Point2D(0, 0))
00033 , m_boundingBox(Point2D(0, 0))
00034 , m_closestPoint(Point2D(0, 0))
00035 , m_contourPoints()
00036 , m_vehicleWLANid(0)
00037 , m_objectHeight(0)
00038 , m_objectHeightSigma(0)
00039 , m_objectMass(0)
00040 , m_maxAbsoluteVelocity(NaN_double)
00041 , m_normalizedMeanPointDist(0)
00042 , m_totalTrackingDuration(0)
00043 , m_totalTrackedPathLength(0)
00044 , m_isValid(true)
00045 {
00046 }
00047
00048 Object::~Object()
00049 {
00050 }
00051
00052 bool Object::operator==(const Object& other) const
00053 {
00054 bool b =
00055 m_objectId == other.m_objectId
00056 && m_flags == other.m_flags
00057 && m_objectAge == other.m_objectAge
00058 && m_hiddenStatusAge == other.m_hiddenStatusAge
00059 && m_timestamp == other.m_timestamp
00060 && m_classification == other.m_classification
00061 && m_classificationAge == other.m_classificationAge
00062 && m_classificationQuality == other.m_classificationQuality
00063 && m_centerPoint == other.m_centerPoint
00064 && m_centerPointSigma == other.m_centerPointSigma
00065 && m_courseAngle == other.m_courseAngle
00066 && m_courseAngleSigma == other.m_courseAngleSigma
00067 && m_relativeVelocity == other.m_relativeVelocity
00068 && m_relativeVelocitySigma == other.m_relativeVelocitySigma
00069 && m_absoluteVelocity == other.m_absoluteVelocity
00070 && m_absoluteVelocitySigma == other.m_absoluteVelocitySigma
00071 && m_objectBox == other.m_objectBox
00072 && m_objectBoxSigma == other.m_objectBoxSigma
00073 && m_boundingBoxCenter == other.m_boundingBoxCenter
00074 && m_boundingBox == other.m_boundingBox
00075 && m_closestPoint == other.m_closestPoint
00076 && m_contourPoints == other.m_contourPoints
00077 && m_objectHeight == other.m_objectHeight
00078 && m_objectHeightSigma == other.m_objectHeightSigma
00079 && m_objectMass == other.m_objectMass
00080 ;
00081 return b;
00082 }
00083
00084
00085 Box2D Object::getBox() const
00086 {
00087 return Box2D(getCenterPoint(), getObjectBox(), getCourseAngle());
00088 }
00089
00090
00091 void Object::setClassificationQuality(double v)
00092 {
00093 assert(v >= 0);
00094 assert(v <= 1);
00095 m_classificationQuality = v;
00096 }
00097
00098 void Object::setCenterPointSigma(const Point2D& v)
00099 {
00100 assert((v.getX() >= 0) || isNaN(v.getX()));
00101 assert((v.getY() >= 0) || isNaN(v.getY()));
00102 m_centerPointSigma = v;
00103 }
00104
00105 void Object::setCourseAngle(double new_angle)
00106 {
00107 double normd_angle = normalizeRadians(new_angle);
00108 if (!fuzzyCompare(normd_angle, new_angle))
00109 {
00110 printWarning("Object::setCourseAngle was called with angle " + ::toString(new_angle, 2) +
00111 " which is outside of its [-pi,pi] definition range (but the calling function should have ensured to normalize into that interval) - normalizing it back into that range now (" +
00112 ::toString(normd_angle, 2) + ").");
00113 new_angle = normd_angle;
00114
00115
00116
00117
00118
00119
00120
00121
00122 }
00123 m_courseAngle = new_angle;
00124 }
00125
00126 void Object::setCourseAngleSigma(double v)
00127 {
00128 assert(v >= 0);
00129 m_courseAngleSigma = v;
00130 }
00131
00132 void Object::setAbsoluteVelocity(const Point2D& v)
00133 {
00134 m_absoluteVelocity = v;
00135 double absolute = v.dist();
00136 if (isNaN(getMaxAbsoluteVelocity())
00137 || absolute > getMaxAbsoluteVelocity())
00138 {
00139 setMaxAbsoluteVelocity(absolute);
00140 }
00141 }
00142
00143 void Object::setAbsoluteVelocitySigma(const Point2D& v)
00144 {
00145 assert((v.getX() >= 0) || isNaN(v.getX()));
00146 assert((v.getY() >= 0) || isNaN(v.getY()));
00147 m_absoluteVelocitySigma = v;
00148 }
00149
00150 void Object::setObjectBox(const Point2D& v)
00151 {
00152 assert((v.getX() >= 0) || isNaN(v.getX()));
00153 assert((v.getY() >= 0) || isNaN(v.getY()));
00154 m_objectBox = v;
00155 }
00156
00157 void Object::setObjectBoxSigma(const Point2D& v)
00158 {
00159 assert((v.getX() >= 0) || isNaN(v.getX()));
00160 assert((v.getY() >= 0) || isNaN(v.getY()));
00161 m_objectBoxSigma = v;
00162 }
00163
00164 void Object::setBoundingBox(const Point2D& v)
00165 {
00166 assert((v.getX() >= 0) || isNaN(v.getX()));
00167 assert((v.getY() >= 0) || isNaN(v.getY()));
00168 m_boundingBox = v;
00169 }
00170
00171 void Object::setBoundingBoxCenter(const Point2D& v)
00172 {
00173 m_boundingBoxCenter = v;
00174 }
00175
00176 void Object::setObjectHeightSigma(double v)
00177 {
00178 assert(v >= 0);
00179 m_objectHeightSigma = v;
00180 }
00181
00182 void Object::setObjectMass(double v)
00183 {
00184 assert(v >= 0);
00185 m_objectMass = v;
00186 }
00187
00188 void Object::setContourPoints(const Polygon2D& v)
00189 {
00190 assert(v.size() <= 0xff);
00191 m_contourPoints = v;
00192 }
00193
00194 void Object::addContourPoint(const Point2D cp)
00195 {
00196 assert(m_contourPoints.size() < 0xff);
00197 m_contourPoints.push_back(cp);
00198 }
00199
00200
00201 std::string Object::toString() const
00202 {
00203 std::string text = "Object: ";
00204 text += "id=" + ::toString(m_objectId);
00205 text += ", flags=" + ::toString(m_flags);
00206 text += ", objAge=" + ::toString(m_objectAge);
00207 text += ", hiddenStatusAge=" + ::toString(m_hiddenStatusAge);
00208 text += ", timestamp=" + m_timestamp.toString();
00209 text += std::string(", classification=") + objectClassificationToString(m_classification);
00210
00211 text += ", classificationAge=" + ::toString(m_classificationAge);
00212
00213 text += ", classificationQuality=" + ::toString(m_classificationQuality, 2);
00214
00215 text += ", centerPoint=" + m_centerPoint.toString();
00216 text += ", centerPointSigma=" + m_centerPointSigma.toString();
00217
00218 text += ", courseAngle=" + ::toString(m_courseAngle, 2);
00219 text += ", courseAngleSigma=" + ::toString(m_courseAngleSigma, 2);
00220
00221 text += ", relativeVelocity=" + m_relativeVelocity.toString();
00222 text += ", relativeVelocitySigma=" + m_relativeVelocitySigma.toString();
00223
00224 text += ", absoluteVelocity=" + m_absoluteVelocity.toString();
00225 text += ", absoluteVelocitySigma=" + m_absoluteVelocitySigma.toString();
00226
00227 text += ", objectBox=" + m_objectBox.toString();
00228 text += ", objectBoxSigma=" + m_objectBoxSigma.toString();
00229
00230 text += ", boundingBox=" + m_boundingBox.toString();
00231 text += ", closestPoint=" + m_closestPoint.toString();
00232
00233 text += ", contourPointsNum=" + ::toString(m_contourPoints.size());
00234 text += ", contourPoints=" + Polygon2D(m_contourPoints).toString();
00235
00236 text += ", vehicleWLANid=" + ::toString(m_vehicleWLANid, 2);
00237 text += ", objectHeight=" + ::toString(m_objectHeight, 2);
00238 text += ", objectHeightSigma=" + ::toString(m_objectHeightSigma, 2);
00239 text += ", objectMass=" + ::toString(m_objectMass, 2);
00240
00241 text += ", maxAbsoluteVelocity=" + ::toString(m_maxAbsoluteVelocity, 2);
00242 text += ", normalizedMeanPointDist=" + ::toString(m_normalizedMeanPointDist, 2);
00243 text += ", totalTrackingDuration=" + ::toString(m_totalTrackingDuration, 2);
00244 text += ", totalTrackedPathLength=" + ::toString(m_totalTrackedPathLength, 2);
00245
00246 return text;
00247 }
00248
00249 #define TYPE_TO_STR(tstr) tstr : return #tstr
00250
00251 const char* Object::objectClassificationToString(ObjectClassification v)
00252 {
00253 switch (v)
00254 {
00255 case TYPE_TO_STR ( Unclassified );
00256 case TYPE_TO_STR ( UnknownSmall );
00257 case TYPE_TO_STR ( UnknownBig );
00258 case TYPE_TO_STR ( Pedestrian );
00259 case TYPE_TO_STR ( Bike );
00260 case TYPE_TO_STR ( Car );
00261 case TYPE_TO_STR ( Truck );
00262 case TYPE_TO_STR ( Structure_Pylon );
00263 case TYPE_TO_STR ( Structure_Beacon );
00264 case TYPE_TO_STR ( Structure_GuardRail );
00265 case TYPE_TO_STR ( Structure_ConcreteBarrier );
00266 case TYPE_TO_STR ( NumClasses );
00267 case TYPE_TO_STR ( Unknown );
00268 default:
00269 throw std::invalid_argument("Unknown object classification " + ::toString(int(v)));
00270 return "<unknown>";
00271 }
00272 }
00273
00274 Object::ObjectClassification Object::stringToObjectClassification(const std::string& s)
00275 {
00276 if (s == "Unclassified" || s == "Unclass")
00277 return Unclassified;
00278 else if (s == "UnknownSmall" || s == "us")
00279 return UnknownSmall;
00280 else if (s == "UnknownBig" || s == "UB")
00281 return UnknownBig;
00282 else if (s == "Pedestrian" || s == "Ped")
00283 return Pedestrian;
00284 else if (s == "Bike")
00285 return Bike;
00286 else if (s == "Car")
00287 return Car;
00288 else if (s == "Truck")
00289 return Truck;
00290 else if (s == "Structure_Pylon" || s == "Pylon")
00291 return Structure_Pylon;
00292 else if (s == "Structure_Beacon" || s == "Bcn")
00293 return Structure_Beacon;
00294 else if (s == "Structure_GuardRail" || s == "GrdRl")
00295 return Structure_GuardRail;
00296 else if (s == "Structure_ConcreteBarrier" || s == "CBar")
00297 return Structure_ConcreteBarrier;
00298 else if (s == "NumClasses" || s == "#Classes")
00299 return NumClasses;
00300 else if (s == "Unknown")
00301 return Unknown;
00302 else
00303 {
00304 throw std::invalid_argument("Unknown object classification string \"" + s + "\"");
00305 return Unknown;
00306 }
00307 }
00308
00309 std::string Object::objectClassificationToStringWithNum(ObjectClassification v)
00310 {
00311 const std::string s = objectClassificationToString(v);
00312 return s + " (" + ::toString((int)v) + ")";
00313 }
00314
00315 const char* Object::objectClassificationToShortString(ObjectClassification v)
00316 {
00317 switch (v)
00318 {
00319 case Unclassified:
00320 return "Unclass";
00321 case UnknownSmall:
00322 return "us";
00323 case UnknownBig:
00324 return "UB";
00325 case Pedestrian:
00326 return "Ped";
00327 case Bike:
00328 return "Bike";
00329 case Car:
00330 return "Car";
00331 case Truck:
00332 return "Truck";
00333 case Structure_Pylon:
00334 return "Pylon";
00335 case Structure_Beacon:
00336 return "Bcn";
00337 case Structure_GuardRail:
00338 return "GrdRl";
00339 case Structure_ConcreteBarrier:
00340 return "CBar";
00341 case NumClasses:
00342 return "#Classes";
00343 case Unknown:
00344 return "Unknown";
00345 default:
00346 throw std::invalid_argument("Unknown object classification " + ::toString(int(v)));
00347 return "<unknown>";
00348 }
00349 }
00350
00351
00352
00353 void Object::getObjectBoxVarCovar(double &var_x, double &var_y, double &covar_xy) const
00354 {
00355
00356 double var_x_obj = sqr(getObjectBoxSigma().getX());
00357 double var_y_obj = sqr(getObjectBoxSigma().getY());
00358
00359
00360 double dCos = std::cos(getCourseAngle());
00361 double dSin = std::sin(getCourseAngle());
00362 double cos_sq = sqr(dCos);
00363 double sin_sq = sqr(dSin);
00364 double cos_sin = dCos * dSin;
00365
00366
00367
00368 var_x = cos_sq * var_x_obj + sin_sq * var_y_obj;
00369 covar_xy = -cos_sin * var_x_obj + cos_sin * var_y_obj;
00370 var_y = sin_sq * var_x_obj + cos_sq * var_y_obj;
00371 }
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 void Object::incrementObjectAge()
00408 {
00409 m_objectAge++;
00410 }
00411
00412 void Object::setMaxAbsoluteVelocity(double v)
00413 {
00414
00415
00416 m_maxAbsoluteVelocity = v;
00417 }
00418 void Object::setNormalizedMeanPointDist(double v)
00419 {
00420
00421
00422 m_normalizedMeanPointDist = v;
00423 }
00424 void Object::setTotalTrackingDuration(double v)
00425 {
00426
00427
00428 m_totalTrackingDuration = v;
00429 }
00430 void Object::setTotalTrackedPathLength(double v)
00431 {
00432
00433
00434 m_totalTrackedPathLength = v;
00435 }
00436
00437 double Object::getMeanAbsoluteVelocity() const
00438 {
00439
00440 return (m_totalTrackingDuration > 0)
00441 ? (m_totalTrackedPathLength / m_totalTrackingDuration)
00442 : 0.0f;
00443 }
00444
00446
00447
00448
00450
00451 ObjectList::ObjectList()
00452 : base_class()
00453 {
00454 m_datatype = Datatype_Objects;
00455 m_timestamp.set(0.0);
00456 }
00457
00458 bool ObjectList::operator==(const ObjectList& other) const
00459 {
00460 return (m_timestamp == other.m_timestamp)
00461 && (static_cast<const base_class&>(*this)
00462 == static_cast<const base_class&>(other));
00463 }
00464
00465
00466 void ObjectList::setTimestamp(const Time& timestamp)
00467 {
00468 m_timestamp = timestamp;
00469 }
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 void ObjectList::incrementObjectAge()
00486 {
00487 iterator obj;
00488 for (obj = begin(); obj != end(); obj++)
00489 {
00490 obj->incrementObjectAge();
00491 }
00492 }
00493
00494 }