Polygon.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*!
  2. * \file Polygon.cpp
  3. * \brief
  4. * \author Gapchich Vladislav
  5. * \date 23/10/11
  6. */
  7. #include "vislearning/cbaselib/Polygon.h"
  8. using namespace OBJREC;
  9. using namespace std;
  10. using namespace NICE;
  11. //! A constructor
  12. Polygon::Polygon()
  13. {
  14. points_.clear();
  15. id_ = -1;
  16. unique_id_ = -1;
  17. }
  18. // A copy-constructor
  19. Polygon::Polygon(const Polygon &copy)
  20. {
  21. points_ = PointsList(*(copy.points()));
  22. id_ = copy.id();
  23. unique_id_ = copy.unique_id_;
  24. }
  25. //! A desctructor
  26. Polygon::~Polygon()
  27. {
  28. }
  29. //! appends aPoint coordinate to the end of the point list
  30. void
  31. Polygon::push(const CoordT< int > &aPoint)
  32. {
  33. if (aPoint.x < 0 || aPoint.y < 0) {
  34. return;
  35. /* NOTREACHED */
  36. }
  37. points_.push_back(aPoint);
  38. }
  39. //! overloaded
  40. /*!
  41. * \see push(const CoordT< int > &aPoint)
  42. */
  43. void
  44. Polygon::push(const int &x, const int &y)
  45. {
  46. if (x < 0 || y < 0) {
  47. return;
  48. /* NOTREACHED */
  49. }
  50. CoordT< int > point;
  51. point.x = x;
  52. point.y = y;
  53. points_.push_back(point);
  54. }
  55. //! Sets a category ID(label ID) for the polygon
  56. /*!
  57. * /param[in] anID should not be less than zero
  58. */
  59. void
  60. Polygon::setID(const int &anID)
  61. {
  62. if (anID < 0) {
  63. return;
  64. /* NOTREACHED */
  65. }
  66. this->id_ = anID;
  67. }
  68. //! returns a constant pointer to the list of polygon points(coordinates)
  69. const PointsList *
  70. Polygon::points() const
  71. {
  72. return &points_;
  73. }
  74. //! deletes last added point of the polygon and returns it
  75. CoordT< int >
  76. Polygon::pop()
  77. {
  78. CoordT< int > ret = points_.back();
  79. points_.pop_back();
  80. return ret;
  81. }
  82. //! returns a category ID of the polygon
  83. int
  84. Polygon::id() const
  85. {
  86. return id_;
  87. }
  88. /*
  89. *
  90. */