ObjectDataAngular.cpp 3.0 KB

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