CrossT.tcc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libimage - An image/template for new NICE libraries
  4. * See file License for license information.
  5. */
  6. #include "core/image/CrossT.h"
  7. #include "core/image/LineT.h"
  8. namespace NICE {
  9. // Constructors:
  10. // -------------
  11. template<class P>
  12. CrossT<P>::CrossT(const Coord &_center, const unsigned int _halfWidth,
  13. bool _diagonal)
  14. : center(_center), halfWidth(_halfWidth), diagonal(_diagonal)
  15. {
  16. }
  17. template<class P>
  18. CrossT<P>::CrossT(const Coord &_center, const unsigned int _halfWidth,
  19. bool _diagonal, const ColorT<P>& _defaultColor)
  20. : Drawable<P>(_defaultColor), center(_center), halfWidth(_halfWidth),
  21. diagonal(_diagonal)
  22. {
  23. }
  24. template<class P>
  25. CrossT<P>::CrossT(const CrossT<P>& ex) : Drawable<P>(ex)
  26. {
  27. *this = ex;
  28. }
  29. // Operators:
  30. // ----------
  31. template<class P>
  32. CrossT<P>& CrossT<P>::operator=(const CrossT<P>& ex)
  33. {
  34. center = ex.center;
  35. this->halfWidth = ex.halfWidth;
  36. this->defaultColor = ex.defaultColor;
  37. return *this;
  38. }
  39. template<class P>
  40. bool CrossT<P>::operator==(const CrossT<P>& ex) const
  41. {
  42. if(center == ex.center &&
  43. this->halfWidth == ex.halfWidth &&
  44. this->defaultColor == ex.defaultColor)
  45. return true;
  46. else
  47. return false;
  48. }
  49. template<class P>
  50. bool CrossT<P>::operator!=(const CrossT<P>& ex) const {
  51. return !(this->operator==(ex));
  52. }
  53. // Methods:
  54. // --------
  55. template<class P>
  56. void CrossT<P>::doDraw(ColorImageT<P> &image, const ColorT<P>& color) const
  57. {
  58. const int x = center.x;
  59. const int y = center.y;
  60. const int left = center.x - halfWidth;
  61. const int right = center.x + halfWidth;
  62. const int top = center.y - halfWidth;
  63. const int bottom = center.y + halfWidth;
  64. if (diagonal) {
  65. LineT<P> line1(Coord(left, top), Coord(right, bottom));
  66. LineT<P> line2(Coord(left, bottom), Coord(right, top));
  67. line1.draw(image, color);
  68. line2.draw(image, color);
  69. } else {
  70. LineT<P> line1(Coord(left, y), Coord(right, y));
  71. LineT<P> line2(Coord(x, top), Coord(x, bottom));
  72. line1.draw(image, color);
  73. line2.draw(image, color);
  74. }
  75. }
  76. template<class P>
  77. void CrossT<P>::doDraw(ImageT<P> &image, const P& gray) const
  78. {
  79. const int x = center.x;
  80. const int y = center.y;
  81. const int left = center.x - halfWidth;
  82. const int right = center.x + halfWidth;
  83. const int top = center.y - halfWidth;
  84. const int bottom = center.y + halfWidth;
  85. if (diagonal) {
  86. LineT<P> line1(Coord(left, top), Coord(right, bottom));
  87. LineT<P> line2(Coord(left, bottom), Coord(right, top));
  88. line1.draw(image, gray);
  89. line2.draw(image, gray);
  90. } else {
  91. LineT<P> line1(Coord(left, y), Coord(right, y));
  92. LineT<P> line2(Coord(x, top), Coord(x, bottom));
  93. line1.draw(image, gray);
  94. line2.draw(image, gray);
  95. }
  96. }
  97. // Destructor:
  98. // -----------
  99. template<class P>
  100. CrossT<P>::~CrossT()
  101. {
  102. }
  103. }; // namespace NICE