nouveau fichier : include/ArrayTree/Border.tpp

nouveau fichier : include/TreeBuilder.tpp
	nouveau fichier : include/triskeleBase.tpp
This commit is contained in:
Git Merciol 2018-02-18 08:25:25 +01:00
parent ed9141d5c5
commit 4b4bbe889d
3 changed files with 258 additions and 0 deletions

View File

@ -0,0 +1,82 @@
#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

43
include/TreeBuilder.tpp Normal file
View File

@ -0,0 +1,43 @@
#ifndef _OTB_TRISKELE_TREE_BUILDER_TPP
#define _OTB_TRISKELE_TREE_BUILDER_TPP
#include "Tree.hpp"
#include "triskeleBase.hpp"
inline void
TreeBuilder::buildTree (Tree &tree, TreeBuilder &builder) {
builder.buildTree (tree);
}
inline void
TreeBuilder::buildTree (Tree &tree, TreeBuilder &&builder) {
builder.buildTree (tree);
}
inline void
TreeBuilder::buildTree (Tree &tree) {
std::cout << "Test" << std::endl;
}
inline void
TreeBuilder::updateAttributes (Tree &tree) {
leafCount = tree.leafCount;
nodeCount = tree.nodeCount;
leafParents = tree.leafParents;
compParents = tree.compParents;
children = tree.children;
childCount = tree.childCount;
}
inline DimNodeId
TreeBuilder::getCompCount () const {
return nodeCount-leafCount;
}
inline void
TreeBuilder::setNodeCount (Tree &tree, DimNodeId nodeCount) {
tree.setNodeCount (nodeCount);
this->nodeCount = nodeCount;
}
#endif // _OTB_TRISKELE_TREE_BUILDER_TPP

133
include/triskeleBase.tpp Normal file
View File

@ -0,0 +1,133 @@
#ifndef _OTB_TRISKELE_BASE_TPP
#define _OTB_TRISKELE_BASE_TPP
inline
Point::Point ()
: x (0),
y (0) {
}
inline
Point::Point (const DimSideImg &abs, const DimSideImg &ord)
: x (abs),
y (ord) {
}
inline bool
operator== (const Point &p1, const Point &p2) {
return p1.x == p2.x && p1.y == p2.y;
}
inline std::ostream &
operator << (std::ostream &out, const Point &p) {
return out << "(" << p.x << "," << p.y << ")";
}
inline
Size::Size ()
: width (0),
height (0) {
}
inline
Size::Size (const DimSideImg &w, const DimSideImg &h)
: width (w),
height (h) {
}
inline bool
operator== (const Size &s1, const Size &s2) {
return s1.width == s2.width && s1.height == s2.height;
}
inline std::ostream &
operator << (std::ostream &out, const Size &s) {
return out << "[" << s.width << "," << s.height << "]";
}
inline DimImg
pointToId (const Size &size, const Point &p) {
return (DimImg)p.x + (DimImg)p.y * size.width;
}
inline Point
idToPoint (const Size &size, const DimImg &id) {
return Point(id % size.width, id / size.width);
}
inline
Rect::Rect ()
: x (0),
y (0),
width (0),
height (0) {
}
inline
Rect::Rect (const Rect &rect)
: x (rect.x),
y (rect.y),
width (rect.width),
height (rect.height) {
}
inline
Rect::Rect (const Point &orig, const Size &size)
: x (orig.x),
y (orig.y),
width (size.width),
height (size.height) {
}
inline
Rect::Rect (const DimSideImg &abs, const DimSideImg &ord, const DimSideImg &w, const DimSideImg &h)
: x (abs),
y (ord),
width (w),
height (h) {
}
inline bool
operator== (const Rect &r1, const Rect &r2) {
return r1.x == r2.x && r1.y == r2.y && r1.width == r2.width && r1.height == r2.height;
}
inline std::ostream &
operator << (std::ostream &out, const Rect &r) {
return out << "[" << r.x << "," << r.y << " " << r.width << "x" << r.height << "]";
}
inline DimImg point2idx (const Size &size, const Point &p) {
return DimImg (p.x) + DimImg (p.y)*DimImg (size.width);
}
inline Point
idx2point (const Size &size, const DimImg &idx) {
return Point (idx % size.width, idx / size.width);
}
template <typename DimImg>
inline std::ostream &
printMap (std::ostream &out, const DimImg *map, const Size &size, DimNodeId maxValues) {
if (size.width > printMapMaxSide || size.height > printMapMaxSide) {
return out << "map too big to print!" << std::endl;
}
if (maxValues == 0)
maxValues = ((DimNodeId) size.width)*size.height;
for (DimSideImg y = 0; y < size.height; ++y) {
for (DimSideImg x = 0; x < size.width; ++x, ++map, --maxValues) {
if (!maxValues)
return out;
if (*map == DimImg_MAX)
out << " M";
else
out << std::setw(3) << *map;
}
out << std::endl;
}
return out;
}
#endif // _OTB_TRISKELE_BASE_TPP