#ifndef _OTB_TRISKELE_ARRAY_TREE_BORDER_TPP #define _OTB_TRISKELE_ARRAY_TREE_BORDER_TPP inline DimImg Border::getPixelsCount (const Size &size) { return DimImg (size.width)*DimImg (size.height); } inline DimImg Border::getMapLength (DimImg pixelsCount) { return (pixelsCount+7)/8; } inline bool Border::exists () const { return map.size (); } inline bool Border::isBorder (DimImg idx) const { BOOST_ASSERT (idx < pixelsCount); return map.size () ? map[idx/8] & (1 << (idx%8)) : defaultVal; } inline bool Border::isBorder (const Point &p) const { BOOST_ASSERT (p.x < size.width && p.y < size.height); return isBorder (point2idx (size, p)); } inline void Border::clearBorder (DimImg idx) { if (!map.size ()) createMap (); BOOST_ASSERT (idx < pixelsCount); map[idx/8] &= ~(1 << (idx%8)); } inline void Border::clearBorder (const Point &p) { clearBorder (point2idx (size, p)); } inline void Border::setBorder (DimImg idx) { if (!map.size ()) createMap (); BOOST_ASSERT (idx < pixelsCount); map[idx/8] |= (1 << (idx%8)); } inline void Border::setBorder (const Point &p) { setBorder (point2idx (size, p)); } inline Border::Border () : pixelsCount (0), mapLength (0), size (), map (), defaultVal (false) { } inline Border::Border (const Size &size, bool defaultVal) : pixelsCount (getPixelsCount (size)), mapLength (getMapLength (pixelsCount)), size (size), map (), defaultVal (defaultVal) { } inline Border::Border (const Border &border, const Rect &tile) : size (tile.width, tile.height), map (), defaultVal (border.defaultVal) { pixelsCount = getPixelsCount (size); mapLength = getMapLength (pixelsCount); if (!border.map.size ()) return; // XXX todo // width >= 8 => for bytes // width < 8 => for bits BOOST_ASSERT (false); } inline Border::~Border () { } inline void Border::reset (bool defaultVal) { this->defaultVal = defaultVal; map.clear (); } inline void Border::createMap () { map.assign (mapLength, defaultVal ? 0xFF : 0); if (!(mapLength && defaultVal)) return; map[mapLength-1] &= 0xFF >> (8-(pixelsCount%8))%8; } inline const Size & Border::getSize () const { return size; } inline DimImg Border::borderCount () { DimImg result = 0; for (DimImg i = 0; i < mapLength; ++i) result += bitCount[map[i]]; return result; } inline ostream &operator << (ostream &out, const Border &border) { if (border.size.width > printMapMaxSide || border.size.height > printMapMaxSide) { return out << "map too big to print!" << std::endl; } for (DimSideImg y = 0, idx = 0; y < border.size.height; ++y) { for (DimSideImg x = 0; x < border.size.width; ++x, ++idx) out << (border.isBorder (idx) ? " B " : " - "); out << endl; } return out; } #endif // _OTB_TRISKELE_ARRAY_TREE_BORDER_HPP