ObjectData3D.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Created by wrede on 04.05.16.
  3. //
  4. #include "ObjectData3D.h"
  5. #include "../util/MyMath.h"
  6. namespace core
  7. {
  8. ObjectData3D::ObjectData3D(size_t frame_index, cv::Point3d position)
  9. : ObjectData(frame_index),
  10. position_(position),
  11. temporal_weight_(1.0),
  12. spatial_weight_(1.0)
  13. {
  14. }
  15. void ObjectData3D::SetTemporalWeight(double weight)
  16. {
  17. temporal_weight_ = weight;
  18. }
  19. void ObjectData3D::SetSpatialWeight(double weight)
  20. {
  21. spatial_weight_ = weight;
  22. }
  23. cv::Point3d ObjectData3D::GetPosition() const
  24. {
  25. return position_;
  26. }
  27. double ObjectData3D::GetTemporalWeight() const
  28. {
  29. return temporal_weight_;
  30. }
  31. double ObjectData3D::GetSpatialWeight() const
  32. {
  33. return spatial_weight_;
  34. }
  35. double ObjectData3D::CompareTo(ObjectDataPtr obj) const
  36. {
  37. ObjectData3DPtr obj_3d = std::static_pointer_cast<ObjectData3D>(obj);
  38. double d_temp = obj_3d->GetFrameIndex() - GetFrameIndex();
  39. double d_spat = util::MyMath::EuclideanDistance(position_, obj_3d->position_);
  40. return d_temp * temporal_weight_ + d_spat * spatial_weight_;
  41. }
  42. ObjectDataPtr ObjectData3D::Interpolate(ObjectDataPtr obj,
  43. double fraction) const
  44. {
  45. ObjectDataPtr obj_in = ObjectData::Interpolate(obj, fraction);
  46. ObjectData3DPtr obj_3d = std::static_pointer_cast<ObjectData3D>(obj);
  47. double x = util::MyMath::Lerp(position_.x, obj_3d->position_.x, fraction);
  48. double y = util::MyMath::Lerp(position_.y, obj_3d->position_.y, fraction);
  49. double z = util::MyMath::Lerp(position_.z, obj_3d->position_.z, fraction);
  50. ObjectData3DPtr obj_out(
  51. new ObjectData3D(obj_in->GetFrameIndex(), cv::Point3d(x, y, z)));
  52. return obj_out;
  53. }
  54. void ObjectData3D::Print(std::ostream& os) const
  55. {
  56. os << "ObjectData3D{"
  57. << "frame: " << GetFrameIndex() << ","
  58. << "x: " << position_.x << ","
  59. << "y: " << position_.y << ","
  60. << "z: " << position_.z << "}";
  61. }
  62. void ObjectData3D::Visualize(cv::Mat& image, cv::Scalar& color) const
  63. {
  64. double x = position_.x * image.cols;
  65. double y = position_.y * image.rows;
  66. int r = (int) (0.005 * (image.rows + image.cols) * 0.5);
  67. cv::circle(image, cv::Point2d(x, y), r, color);
  68. }
  69. }