ObjectDataAngular.cpp 3.0 KB

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