#ifndef _OTB_TRISKELE_BASE_HPP #define _OTB_TRISKELE_BASE_HPP #include #include #include #include #include #define DimImg_MAX UINT32_MAX namespace triskele { /*! Image size type */ typedef uint32_t DimSideImg; /*! Number of pixels */ typedef uint32_t DimImg; /*! Number of nodes */ typedef uint32_t DimNodeId; /*! Compte le nombre de bits utilisés pour chaque nombre : bitCount[nombre] = nombre de bits*/ extern int bitCount[]; struct Point { DimSideImg x, y; Point () : x (0), y (0) {} Point (const DimSideImg &abs, const DimSideImg &ord) : x (abs), y (ord) {} }; inline std::ostream &operator << (std::ostream &out, const Point &p) { return out << "(" << p.x << "," << p.y << ")"; } extern Point NullPoint; struct Size { DimSideImg width, height; Size () : width (0), height (0) {} Size (const DimSideImg &w, const DimSideImg &h) : width (w), height (h) {} }; 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); } extern Size NullSize; struct Rect { DimSideImg x, y, width, height; Rect () : x (0), y (0), width (0), height (0) {} Rect (const Rect &rect) : x (rect.x), y (rect.y), width (rect.width), height (rect.height) {} Rect (const Point &orig, const Size &size) : x (orig.x), y (orig.y), width (size.width), height (size.height) {} Rect (const DimSideImg &abs, const DimSideImg &ord, const DimSideImg &w, const DimSideImg &h) : x (abs), y (ord), width (w), height (h) {} }; inline std::ostream &operator << (std::ostream &out, const Rect &r) { return out << "[" << r.x << "," << r.y << " " << r.width << "x" << r.height << "]"; } extern Rect NullRect; /*! Convertit un point d'un tableau (on peut imaginer une image à 2 dimension) en un index */ inline DimImg point2idx (const Size &size, const Point &p) { return DimImg (p.x) + DimImg (p.y)*DimImg (size.width); } /*! Convertit un index d'un tableau (on peut imaginer une image à 2 dimension) en point correspondant à des coordonnées */ inline Point idx2point (const Size &size, const DimImg &idx) { return Point (idx % size.width, idx / size.width); } /*! Affiche le contenu d'un tableau en spécifiant sa taille */ template inline std::ostream &printMap (std::ostream &out, const DimImg *map, const Size &size) { for (DimSideImg y = 0; y < size.height; ++y) { for (DimSideImg x = 0; x < size.width; ++x, ++map) out << std::setw(3) << *map; out << std::endl; } return out; } } // namespace triskele #endif // _OTB_TRISKELE_BASE_HPP