RectangleT.tcc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. /*****************************************************************************/
  7. /*! \file RectangleT.C
  8. \brief RectangleT class definitions
  9. */
  10. #include "core/image/RectangleT.h"
  11. namespace NICE {
  12. // Constructors:
  13. // -------------
  14. template<class P>
  15. RectangleT<P>::RectangleT(const Coord& _begin, const Coord& _end)
  16. : begin(_begin), end(_end) {
  17. }
  18. template<class P>
  19. RectangleT<P>::RectangleT(const Coord &_begin, const Coord &_end,
  20. const ColorT<P>& _defaultColor)
  21. : Drawable<P>(_defaultColor) {
  22. RectangleT<P>(begin, end);
  23. }
  24. template<class P>
  25. RectangleT<P>::RectangleT(const int x, const int y, const int width, const int height)
  26. : begin(Coord(x,y)), end(Coord(x+width,y+height)) {
  27. }
  28. template<class P>
  29. RectangleT<P>::RectangleT(const int x, const int y, const int width, const int height,
  30. const ColorT<P>& _defaultColor)
  31. : begin(Coord(x,y)), end(Coord(x+width,y+height)), Drawable<P>(_defaultColor) {
  32. }
  33. template<class P>
  34. RectangleT<P>::RectangleT(const Rect& rect)
  35. : begin(Coord(rect.left, rect.top)), end(Coord(rect.left+rect.width, rect.top+rect.height)) {
  36. }
  37. template<class P>
  38. RectangleT<P>::RectangleT(const Rect& rect, const ColorT<P>& _defaultColor)
  39. : begin(Coord(rect.left, rect.top)), end(Coord(rect.left+rect.width, rect.top+rect.height)),
  40. Drawable<P>(_defaultColor) {
  41. }
  42. template<class P>
  43. RectangleT<P>::RectangleT(const RectangleT<P>& ex) {
  44. *this=ex;
  45. }
  46. // Operators:
  47. // ----------
  48. template<class P>
  49. RectangleT<P>& RectangleT<P>::operator=(const RectangleT<P>& ex) {
  50. begin = ex.begin;
  51. end = ex.end;
  52. this->defaultColor = ex.defaultColor;
  53. return *this;
  54. }
  55. template<class P>
  56. bool RectangleT<P>::operator==(const RectangleT<P>& ex) const {
  57. if(begin==ex.begin &&
  58. end==ex.end && this->defaultColor==ex.defaultColor)
  59. return true;
  60. return false;
  61. }
  62. template<class P>
  63. bool RectangleT<P>::operator!=(const RectangleT<P>& ex) const {
  64. return !(this->operator==(ex));
  65. }
  66. // Methods:
  67. // --------
  68. template<class P>
  69. void RectangleT<P>::doDraw(ColorImageT<P> &image, const ColorT<P>& color) const {
  70. // clip rect coords to image boundaries
  71. Coord b(begin);
  72. Coord e(end);
  73. Ipp32s width = image.width();
  74. Ipp32s height = image.height();
  75. b.x = b.x<0?0:b.x;
  76. b.x = b.x>=width?width-1:b.x;
  77. b.y = b.y<0?0:b.y;
  78. b.y = b.y>=height?height-1:b.y;
  79. e.x = e.x<0?0:e.x;
  80. e.x = e.x>=width?width-1:e.x;
  81. e.y = e.y<0?0:e.y;
  82. e.y = e.y>=height?height-1:e.y;
  83. // draw horizontal lines
  84. Ipp8u* pL1 = image.getPixelPointerXY(b.x, b.y);
  85. Ipp8u* pL2 = image.getPixelPointerXY(b.x, e.y);
  86. for(Ipp32s x=b.x; x<=e.x; ++x,pL1+=3,pL2+=3) {
  87. *pL2 = *pL1 = color[0];
  88. *(pL2+1) = *(pL1+1) = color[1];
  89. *(pL2+2) = *(pL1+2) = color[2];
  90. }
  91. // draw vertical lines
  92. pL1 = image.getPixelPointerXY(b.x, b.y);
  93. pL2 = image.getPixelPointerXY(e.x, b.y);
  94. for(Ipp32s y=b.y; y<=e.y; ++y,pL1+=image.getStepsize(),pL2+=image.getStepsize()) {
  95. *pL2 = *pL1 = color[0];
  96. *(pL2+1) = *(pL1+1) = color[1];
  97. *(pL2+2) = *(pL1+2) = color[2];
  98. }
  99. }
  100. template<class P>
  101. void RectangleT<P>::doDraw(ImageT<P> &image, const P& gray) const {
  102. // clip rect coords to image boundaries
  103. Coord b(begin);
  104. Coord e(end);
  105. Ipp32s width = image.width();
  106. Ipp32s height = image.height();
  107. b.x = b.x<0?0:b.x;
  108. b.x = b.x>=width?width-1:b.x;
  109. b.y = b.y<0?0:b.y;
  110. b.y = b.y>=height?height-1:b.y;
  111. e.x = e.x<0?0:e.x;
  112. e.x = e.x>=width?width-1:e.x;
  113. e.y = e.y<0?0:e.y;
  114. e.y = e.y>=height?height-1:e.y;
  115. // draw horizontal lines
  116. Ipp8u* pL1 = image.getPixelPointerXY(b.x, b.y);
  117. Ipp8u* pL2 = image.getPixelPointerXY(b.x, e.y);
  118. for(Ipp32s x=b.x; x<=e.x; ++x,++pL1,++pL2)
  119. *pL2 = *pL1 = gray;
  120. // draw vertical lines
  121. pL1 = image.getPixelPointerXY(b.x, b.y);
  122. pL2 = image.getPixelPointerXY(e.x, b.y);
  123. for(Ipp32s y=b.y; y<=e.y; ++y,pL1+=image.getStepsize(),pL2+=image.getStepsize())
  124. *pL2 = *pL1 = gray;
  125. }
  126. // Destructor:
  127. // -----------
  128. template<class P>
  129. RectangleT<P>::~RectangleT() {
  130. }
  131. }; // namespace NICE