83 lines
1.6 KiB
C++
83 lines
1.6 KiB
C++
#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::isBorder (DimImg idx) const {
|
|
return map ? map[idx/8] & (1 << (idx%8)) : false;
|
|
}
|
|
|
|
inline bool
|
|
Border::isBorder (const Point &p) const {
|
|
return map ? isBorder (pointToId (size, p)) : false;
|
|
}
|
|
|
|
inline void
|
|
Border::clearBorder (DimImg idx) {
|
|
map[idx/8] &= ~(1 << (idx%8));
|
|
}
|
|
|
|
inline void
|
|
Border::clearBorder (const Point &p) {
|
|
clearBorder (pointToId (size, p));
|
|
}
|
|
|
|
inline void
|
|
Border::setBorder (DimImg idx) {
|
|
map[idx/8] |= (1 << (idx%8));
|
|
}
|
|
|
|
inline void
|
|
Border::setBorder (const Point &p) {
|
|
setBorder (pointToId (size, p));
|
|
}
|
|
|
|
inline
|
|
Border::Border ()
|
|
: pixelsCount (0),
|
|
mapLength (0),
|
|
size (),
|
|
map (NULL) {
|
|
}
|
|
|
|
inline
|
|
Border::Border (const Size &size, bool defaultVal)
|
|
: pixelsCount (getPixelsCount (size)),
|
|
mapLength (getMapLength (pixelsCount)),
|
|
size (size) {
|
|
map = new uint8_t [mapLength];
|
|
reset (defaultVal);
|
|
}
|
|
|
|
inline
|
|
Border::~Border () {
|
|
if (map)
|
|
delete [] map;
|
|
}
|
|
|
|
inline void
|
|
Border::reset (bool defaultVal) {
|
|
std::fill_n (map, mapLength, defaultVal ? 0xFF : 0);
|
|
if (!(mapLength && defaultVal))
|
|
return;
|
|
map[mapLength-1] &= 0xFF >> (8-(pixelsCount%8))%8;
|
|
}
|
|
|
|
inline DimImg
|
|
Border::borderCount () {
|
|
DimImg result = 0;
|
|
for (DimImg i = 0; i < mapLength; ++i)
|
|
result += bitCount[map[i]];
|
|
return result;
|
|
}
|
|
|
|
#endif // _OTB_TRISKELE_ARRAY_TREE_BORDER_HPP
|