triskele/include/triskeleBase.tpp
Git Merciol 2683beda1a modifié : CMakeLists.txt
modifié :         CMakeListsOTB.txt
	modifié :         LICENSE
	modifié :         MakefileNoOTB
	modifié :         Readme.html
	modifié :         Readme.txt
	modifié :         data/10m.tif
	modifié :         data/areaThresholds.txt
	modifié :         data/moiThresholds.txt
	modifié :         data/sdThresholds.txt
	modifié :         include/Appli/Option.hpp
	modifié :         include/Appli/Selected.hpp
	modifié :         include/Appli/Selected.tpp
	modifié :         include/ArrayTree/ArrayTreeBuilder.hpp
	modifié :         include/ArrayTree/ArrayTreeBuilder.tpp
	modifié :         include/ArrayTree/Border.hpp
	modifié :         include/ArrayTree/Border.tpp
	modifié :         include/ArrayTree/GraphWalker.hpp
	modifié :         include/ArrayTree/GraphWalker.tpp
	modifié :         include/ArrayTree/Leader.hpp
	modifié :         include/ArrayTree/Leader.tpp
	modifié :         include/ArrayTree/Weight.hpp
	modifié :         include/ArrayTree/Weight.tpp
	modifié :         include/ArrayTree/triskeleArrayTreeBase.hpp
	modifié :         include/ArrayTree/triskeleArrayTreeBase.tpp
	modifié :         include/ArrayTree/triskeleSort.hpp
	modifié :         include/ArrayTree/triskeleSort.tpp
	modifié :         include/AttributeProfiles.hpp
	modifié :         include/AttributeProfiles.tpp
	modifié :         include/Attributes/AreaAttributes.hpp
	modifié :         include/Attributes/AreaAttributes.tpp
	modifié :         include/Attributes/AverageAttributes.hpp
	modifié :         include/Attributes/AverageAttributes.tpp
	modifié :         include/Attributes/MoIAttributes.hpp
	modifié :         include/Attributes/MoIAttributes.tpp
	modifié :         include/Attributes/SDAttributes.hpp
	modifié :         include/Attributes/SDAttributes.tpp
	modifié :         include/Attributes/WeightAttributes.hpp
	modifié :         include/Attributes/WeightAttributes.tpp
	modifié :         include/Attributes/XYAttributes.hpp
	modifié :         include/Attributes/XYAttributes.tpp
	modifié :         include/CompAttribute.hpp
	modifié :         include/CompAttribute.tpp
	modifié :         include/IImage.hpp
	modifié :         include/IImage.tpp
	modifié :         include/QuadTree/QuadTreeBuilder.hpp
	modifié :         include/Tree.hpp
	modifié :         include/Tree.tpp
	modifié :         include/TreeBuilder.hpp
	modifié :         include/TreeBuilder.tpp
	modifié :         include/TreeStats.hpp
	modifié :         include/TreeStats.tpp
	modifié :         include/XMLTree/XMLTreeBuilder.hpp
	modifié :         include/triskeleBase.hpp
	modifié :         include/triskeleBase.tpp
	modifié :         include/triskeleDealThreads.hpp
	modifié :         include/triskeleDealThreads.tpp
	modifié :         include/triskeleDebug.hpp
	modifié :         include/triskeleGdalGetType.hpp
	modifié :         otb-module.cmake
	modifié :         src/Appli/Option.cpp
	modifié :         src/Appli/Selected.cpp
	modifié :         src/ArrayTree/triskeleArrayTreeBase.cpp
	modifié :         src/CMakeLists.txt
	modifié :         src/IImage.cpp
	modifié :         src/PerfArrayTreeBuilder.cpp
	modifié :         src/QuadTree/QuadTreeBuilder.cpp
	modifié :         src/TestArrayTreeBuilder.cpp
	modifié :         src/Tree.cpp
	modifié :         src/TreeStats.cpp
	modifié :         src/XMLTree/XMLTreeBuilder.cpp
	modifié :         src/apGenerator.cpp
	modifié :         src/triskeleBase.cpp
	modifié :         src/triskeleDebug.cpp
2018-03-29 09:34:28 +02:00

200 lines
4.9 KiB
C++
Executable File

#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<typename T>
inline void
Rect::cpToTile (const Size &size, const T* src, vector<T> &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<typename T>
inline void
Rect::cpFromTile (const Size &size, const vector<T> &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<typename T>
inline void
Rect::cpFromTileMove (const Size &size, const vector<T> &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 <typename T>
inline
CPrintMap<T>::CPrintMap (const T *map, const Size &size, DimNodeId maxValues)
: map (map),
size (size),
maxValues (maxValues == 0 ? ((DimNodeId) size.width)*size.height : maxValues) {
}
template <typename T>
inline ostream &
CPrintMap<T>::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 <typename T>
inline CPrintMap<T>
printMap (const T *map, const Size &size, DimNodeId maxValues) {
return CPrintMap<T> (map, size, maxValues);
}
#endif // _OTB_TRISKELE_BASE_TPP