ObjectDataAngular.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // Created by wrede on 19.05.16.
  3. //
  4. #include "ObjectDataAngular.h"
  5. #include "../util/MyMath.h"
  6. namespace core
  7. {
  8. ObjectDataAngular::ObjectDataAngular(size_t frame_index,
  9. const cv::Point2d& position,
  10. double angle)
  11. : ObjectData2D(frame_index, position), angle_(angle), angular_weight_(1.0)
  12. {
  13. }
  14. ObjectDataAngular::ObjectDataAngular(size_t frame_index,
  15. const cv::Point2d& position,
  16. double angle,
  17. double temporal_weight,
  18. double spatial_weight,
  19. double angular_weight)
  20. : ObjectData2D(frame_index, position)
  21. {
  22. angle_ = angle;
  23. angular_weight_ = angular_weight;
  24. SetTemporalWeight(temporal_weight);
  25. SetSpatialWeight(spatial_weight);
  26. }
  27. void ObjectDataAngular::SetAngularWeight(double weight)
  28. {
  29. angular_weight_ = weight;
  30. }
  31. double ObjectDataAngular::GetAngle() const
  32. {
  33. return angle_;
  34. }
  35. double ObjectDataAngular::GetAngularWeight() const
  36. {
  37. return angular_weight_;
  38. }
  39. double ObjectDataAngular::CompareTo(ObjectDataPtr obj) const
  40. {
  41. ObjectDataAngularPtr obj_ang =
  42. std::static_pointer_cast<ObjectDataAngular>(obj);
  43. double d_ang = std::abs(obj_ang->angle_ - angle_);
  44. return ObjectData2D::CompareTo(obj) + d_ang * angular_weight_;
  45. }
  46. ObjectDataPtr ObjectDataAngular::Interpolate(ObjectDataPtr obj,
  47. double fraction) const
  48. {
  49. ObjectData2DPtr obj_in =
  50. std::static_pointer_cast<ObjectData2D>(
  51. ObjectData2D::Interpolate(obj, fraction));
  52. ObjectDataAngularPtr obj_ang =
  53. std::static_pointer_cast<ObjectDataAngular>(obj);
  54. double angle = util::MyMath::Lerp(angle_, obj_ang->angle_, fraction);
  55. ObjectDataAngularPtr obj_out(
  56. new ObjectDataAngular(
  57. obj_in->GetFrameIndex(), obj_in->GetPosition(), angle));
  58. return obj_out;
  59. }
  60. void ObjectDataAngular::Visualize(cv::Mat& image, cv::Scalar& color) const
  61. {
  62. double x = GetPosition().x * image.cols;
  63. double y = GetPosition().y * image.rows;
  64. int r = (int) (0.005 * (image.rows + image.cols) * 0.5);
  65. double a_x = x + cos(angle_) * r * 6.0;
  66. double a_y = y + sin(angle_) * r * 6.0;
  67. cv::circle(image, cv::Point2d(x, y), r, color);
  68. cv::line(image, cv::Point2d(x, y), cv::Point2d(a_x, a_y), color);
  69. }
  70. void ObjectDataAngular::Print(std::ostream& os) const
  71. {
  72. os << "ObjectDataAngular{"
  73. << "f:" << GetFrameIndex() << ", "
  74. << "x:" << GetPosition().x << ", "
  75. << "y:" << GetPosition().y << ", "
  76. << "a:" << GetAngle() << "}";
  77. }
  78. }