/* * NICE-Core - efficient algebra and computer vision methods * - libimage - An image/template for new NICE libraries * See file License for license information. */ /*****************************************************************************/ /*! \file RectangleT.C \brief RectangleT class definitions */ #include "core/image/RectangleT.h" namespace NICE { // Constructors: // ------------- template RectangleT

::RectangleT(const Coord& _begin, const Coord& _end) : begin(_begin), end(_end) { } template RectangleT

::RectangleT(const Coord &_begin, const Coord &_end, const ColorT

& _defaultColor) : Drawable

(_defaultColor) { RectangleT

(begin, end); } template RectangleT

::RectangleT(const int x, const int y, const int width, const int height) : begin(Coord(x,y)), end(Coord(x+width,y+height)) { } template RectangleT

::RectangleT(const int x, const int y, const int width, const int height, const ColorT

& _defaultColor) : begin(Coord(x,y)), end(Coord(x+width,y+height)), Drawable

(_defaultColor) { } template RectangleT

::RectangleT(const Rect& rect) : begin(Coord(rect.left, rect.top)), end(Coord(rect.left+rect.width, rect.top+rect.height)) { } template RectangleT

::RectangleT(const Rect& rect, const ColorT

& _defaultColor) : begin(Coord(rect.left, rect.top)), end(Coord(rect.left+rect.width, rect.top+rect.height)), Drawable

(_defaultColor) { } template RectangleT

::RectangleT(const RectangleT

& ex) { *this=ex; } // Operators: // ---------- template RectangleT

& RectangleT

::operator=(const RectangleT

& ex) { begin = ex.begin; end = ex.end; this->defaultColor = ex.defaultColor; return *this; } template bool RectangleT

::operator==(const RectangleT

& ex) const { if(begin==ex.begin && end==ex.end && this->defaultColor==ex.defaultColor) return true; return false; } template bool RectangleT

::operator!=(const RectangleT

& ex) const { return !(this->operator==(ex)); } // Methods: // -------- template void RectangleT

::doDraw(ColorImageT

&image, const ColorT

& color) const { // clip rect coords to image boundaries Coord b(begin); Coord e(end); Ipp32s width = image.width(); Ipp32s height = image.height(); b.x = b.x<0?0:b.x; b.x = b.x>=width?width-1:b.x; b.y = b.y<0?0:b.y; b.y = b.y>=height?height-1:b.y; e.x = e.x<0?0:e.x; e.x = e.x>=width?width-1:e.x; e.y = e.y<0?0:e.y; e.y = e.y>=height?height-1:e.y; // draw horizontal lines Ipp8u* pL1 = image.getPixelPointerXY(b.x, b.y); Ipp8u* pL2 = image.getPixelPointerXY(b.x, e.y); for(Ipp32s x=b.x; x<=e.x; ++x,pL1+=3,pL2+=3) { *pL2 = *pL1 = color[0]; *(pL2+1) = *(pL1+1) = color[1]; *(pL2+2) = *(pL1+2) = color[2]; } // draw vertical lines pL1 = image.getPixelPointerXY(b.x, b.y); pL2 = image.getPixelPointerXY(e.x, b.y); for(Ipp32s y=b.y; y<=e.y; ++y,pL1+=image.getStepsize(),pL2+=image.getStepsize()) { *pL2 = *pL1 = color[0]; *(pL2+1) = *(pL1+1) = color[1]; *(pL2+2) = *(pL1+2) = color[2]; } } template void RectangleT

::doDraw(ImageT

&image, const P& gray) const { // clip rect coords to image boundaries Coord b(begin); Coord e(end); Ipp32s width = image.width(); Ipp32s height = image.height(); b.x = b.x<0?0:b.x; b.x = b.x>=width?width-1:b.x; b.y = b.y<0?0:b.y; b.y = b.y>=height?height-1:b.y; e.x = e.x<0?0:e.x; e.x = e.x>=width?width-1:e.x; e.y = e.y<0?0:e.y; e.y = e.y>=height?height-1:e.y; // draw horizontal lines Ipp8u* pL1 = image.getPixelPointerXY(b.x, b.y); Ipp8u* pL2 = image.getPixelPointerXY(b.x, e.y); for(Ipp32s x=b.x; x<=e.x; ++x,++pL1,++pL2) *pL2 = *pL1 = gray; // draw vertical lines pL1 = image.getPixelPointerXY(b.x, b.y); pL2 = image.getPixelPointerXY(e.x, b.y); for(Ipp32s y=b.y; y<=e.y; ++y,pL1+=image.getStepsize(),pL2+=image.getStepsize()) *pL2 = *pL1 = gray; } // Destructor: // ----------- template RectangleT

::~RectangleT() { } }; // namespace NICE