ObjectDataAngular.cpp 3.1 KB

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