shapes.hh 1.66 KB
Newer Older
1 2 3 4 5
#pragma once

#include <array>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
6
#include <spdlog/spdlog.h>
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
class Shape
{
public:
  static constexpr int MAX_POINTS{4};
  enum class ShapeType { Square, Triangle };

  /// \brief Default constructor
  Shape() = delete;

  Shape(Shape::ShapeType const t_type);

  /// \brief Copy constructor
  Shape(const Shape &other) = default;

  /// \brief Move constructor
  Shape(Shape &&other) noexcept;

  /// \brief Destructor
  virtual ~Shape() noexcept = default;

  /// \brief  Copy assignment operator
  Shape &operator=(const Shape &other) = delete;

  /// \brief Move assignment operator
  Shape &operator=(Shape &&other) noexcept = delete;

  /// \brief Generates a shape's points
35
  void update(cv::Point &&t_max_pos, int const t_max_size,
36
              int const t_min_size = 1) noexcept;
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

  [[nodiscard]] auto get_points() const noexcept
      -> std::array<cv::Point, Shape::MAX_POINTS> const &
  {
    return points_;
  }

  /// \brief Returns the type of shape described by the object
  [[nodiscard]] auto get_type() const noexcept -> ShapeType const &
  {
    return type_;
  }

  [[nodiscard]] auto get_nb_points() const noexcept
  {
    return nb_points_;
  }

protected:
private:
  void create_square_points(cv::Point const &t_top_left,
                            int const t_size) noexcept;
  void create_triangle_points(cv::Point const &t_top_left,
                              int const t_size) noexcept;

  ShapeType const type_{ShapeType::Square};
  std::array<cv::Point, Shape::MAX_POINTS> points_{
      cv::Point{0, 0}, cv::Point{0, 0}, cv::Point{0, 0}, cv::Point{0, 0}};
  int nb_points_{Shape::MAX_POINTS};
66
};