#ifndef _OTB_TRISKELE_BASE_TPP #define _OTB_TRISKELE_BASE_TPP inline Size::Size () : width (0), height (0) { } inline Size::Size (const Size &size) : width (size.width), height (size.height) { } 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 ostream & operator << (ostream &out, const Size &s) { return out << "[" << s.width << "," << s.height << "]"; } inline Point::Point () : x (0), y (0) { } inline Point::Point (const DimSideImg &abs, const DimSideImg &ord) : x (abs), y (ord) { } inline Point::Point (const Size &size, const DimImg &idx) : x (idx % size.width), y (idx / size.width) { } inline bool operator== (const Point &p1, const Point &p2) { return p1.x == p2.x && p1.y == p2.y; } inline ostream & operator << (ostream &out, const Point &p) { return out << "(" << p.x << "," << p.y << ")"; } inline DimImg point2idx (const Size &size, const Point &p) { return DimImg (p.x) + DimImg (p.y)*DimImg (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 DimImg Rect::relIdx (const Point &p) const { return DimImg (p.x-x) + DimImg (p.y-y)*DimImg (width); } inline DimImg Rect::absIdx (const DimImg &relIdx, const Size &rectSize) const { return (relIdx % width)+x + ((relIdx / width)+y)*rectSize.width; } template inline void Rect::cpToTile (const Size &size, const T* src, vector &dst) const { // XXX no border //SMART_DEF_LOG ("Rect::cpToTile", "rectSize:" << size); const DimImg maxCount = width*height; dst.resize (maxCount); for (DimImg idx = 0; idx < maxCount; ++idx) { dst [idx] = src [absIdx (idx, size)]; //SMART_LOG ("idx:" << idx << " abs:" << absIdx (idx, size)); } // SMART_LOG ("tile:"<< *this << " src/dst:" << endl // << printMap (src, size, 0) << endl // << printMap (&dst[0], Size (width, height), 0)); } template inline void Rect::cpFromTile (const Size &size, const vector &src, T *dst) const { // XXX no border const DimImg maxCount = width*height; //SMART_DEF_LOG ("Rect::cpFromTile", "rectSize:" << size); for (DimImg idx = 0; idx < maxCount; ++idx) { dst [absIdx (idx, size)] = src [idx]; //SMART_LOG ("idx:" << idx << " abs:" << absIdx (idx, size)); } // SMART_LOG ("tile:"<< *this << " src/dst:" << endl // << printMap (&src[0], Size (width, height), 0) << endl // << printMap (dst, size, 0)); } template inline void Rect::cpFromTileMove (const Size &size, const vector &src, T *dst, const T &move) const { // XXX no border const DimImg maxCount = width*height; DEF_LOG ("Rect::cpFromTileTrans", "rectSize:" << size << " move:" << move); for (DimImg idx = 0; idx < maxCount; ++idx) { dst [absIdx (idx, size)] = src [idx] + move; //LOG ("idx:" << idx << " abs:" << absIdx (idx, size)); } SMART_LOG ("tile:"<< *this << " src/dst:" << endl << printMap (&src[0], Size (width, height), 0) << endl << printMap (dst, size, 0)); } 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 ostream & operator << (ostream &out, const Rect &r) { return out << "[" << r.x << "," << r.y << " " << r.width << "x" << r.height << "]"; } // ======================================== template inline CPrintMap::CPrintMap (const T *map, const Size &size, DimNodeId maxValues) : map (map), size (size), maxValues (maxValues == 0 ? ((DimNodeId) size.width)*size.height : maxValues) { } template inline ostream & CPrintMap::print (ostream &out) const { if (size.width > printMapMaxSide || size.height > printMapMaxSide) { return out << "map too big to print!" << endl; } const T *map2 = map; DimNodeId countDown = maxValues; for (DimSideImg y = 0; y < size.height; ++y) { for (DimSideImg x = 0; x < size.width; ++x, ++map2, --countDown) { if (!countDown) return out; if ((DimImg (*map2)) == DimImg_MAX) out << " M "; else // XXX if T == uint8_t => print char :-( out << setw(3) << *map2 << " "; } out << endl; } return out; } template inline CPrintMap printMap (const T *map, const Size &size, DimNodeId maxValues) { return CPrintMap (map, size, maxValues); } #endif // _OTB_TRISKELE_BASE_TPP