Program Listing for File Line2D.h

Return to documentation for file (include/apriltag_mit/AprilTags/Line2D.h)

#ifndef APRILTAGS_LINE2D_H_
#define APRILTAGS_LINE2D_H_

#include <cmath>
#include <utility>
#include <vector>
#include <opencv2/core/core.hpp>

#include "apriltag_mit/AprilTags/MathUtil.h"
#include "apriltag_mit/AprilTags/Segment.h"

namespace AprilTags {

class Line2D {
 public:
  Line2D() = default;

  Line2D(float k, float b);

  Line2D(const Segment &seg);

  Line2D(float dx, float dy, const cv::Point2f &p);

  Line2D(const cv::Point2f &p1, const cv::Point2f &p2);

  float GetLineCoordinate(const cv::Point2f &p);

  cv::Point2f GetPointOfCoordinate(float coord);

  // parallel.
  cv::Point2f IntersectionWidth(const Line2D &line) const;

  static Line2D LsqFitXyw(const std::vector<cv::Point3f> &xyw);

  float dx() const { return dx_; }
  float dy() const { return dy_; }
  float x() const { return p_.x; }
  float y() const { return p_.y; }
  const cv::Point2f &p() const { return p_; }

 protected:
  void NormalizeSlope();
  void NormalizeP();

 private:
  float dx_ = 0;
  float dy_ = 0;

  cv::Point2f p_;
  bool slope_normalized_ = false;
  bool p_normalized_ = false;
};

}  // namespace AprilTags

#endif  // APRILTAGS_GLINE2D_H_