triskele/include/ArrayTree/Weight.tpp
Git Merciol ed9141d5c5 modifié : include/ArrayTree/ArrayTreeBuilder.hpp
modifié :         include/ArrayTree/ArrayTreeBuilder.tpp
	modifié :         include/ArrayTree/Border.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/IImage.hpp
	modifié :         include/IImage.tpp
	modifié :         include/Tree.hpp
	modifié :         include/Tree.tpp
	modifié :         include/TreeBuilder.hpp
	modifié :         include/XMLTree/XMLTreeBuilder.hpp
	modifié :         include/triskeleBase.hpp
	modifié :         include/triskeleDealThreads.hpp
	modifié :         include/triskeleDealThreads.tpp
	modifié :         include/triskeleDebug.hpp
	modifié :         include/triskeleGdalGetType.hpp
	nouveau fichier : src/IImage.cpp
	modifié :         src/QuadTree/QuadTreeBuilder.cpp
	modifié :         src/Tree.cpp
	modifié :         src/testMain.cpp
	modifié :         src/triskeleDebug.cpp
2018-02-18 08:24:25 +01:00

291 lines
8.3 KiB
C++

#ifndef _OTB_TRISKELE_ARRAY_TREE_WEIGHT_TPP
#define _OTB_TRISKELE_ARRAY_TREE_WEIGHT_TPP
// ========================================
template <typename PixelT>
inline DimNodeId
WeightBase<PixelT>::pointIdx (const Point &p) const {
return point2idx (size, p);
}
template <typename PixelT>
inline const Size &
WeightBase<PixelT>::getSize () const {
return size;
}
template <typename PixelT>
inline const PixelT &
WeightBase<PixelT>::getValue (const DimImg &idx) const {
return pixels[idx];
}
template <typename PixelT>
inline const PixelT &
WeightBase<PixelT>::getValue (const Point &p) const {
return getValue (pointIdx (p));
}
template <typename PixelT>
inline bool
WeightBase<PixelT>::getDecr () const {
return false;
}
template <typename PixelT>
inline const PixelT &
WeightBase<PixelT>::getMaxPixel () const {
return maxPixel;
}
template <typename PixelT>
inline const PixelT &
WeightBase<PixelT>::getHalfPixel () const {
return halfPixel;
}
template <typename PixelT>
inline PixelT *
WeightBase<PixelT>::allocAP (const DimNodeId &nodeCapacity) const {
return new PixelT [nodeCapacity];
}
template <typename PixelT>
inline
WeightBase<PixelT>::WeightBase (const PixelT *pixels, const Size &size)
: pixels (pixels),
size (size) {
maxPixel = std::numeric_limits<PixelT>::max ();
// only if unsigned
halfPixel = maxPixel / 2;
if (typeid (PixelT) != typeid (float))
halfPixel++;
}
// ========================================
template <typename PixelT, typename WeightT>
inline
WeightBase2<PixelT, WeightT>::WeightBase2 (const PixelT *pixels, const Size &size)
: WB (pixels, size) {
}
template <typename PixelT, typename WeightT>
inline bool
WeightBase2<PixelT, WeightT>::isWeightInf (const WeightT &a, const WeightT &b) {
return a < b;
}
template <typename PixelT, typename WeightT>
inline bool
WeightBase2<PixelT, WeightT>::isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b) {
return isWeightInf (a.weight, b.weight);
}
template <typename PixelT, typename WeightT>
inline void
WeightBase2<PixelT, WeightT>::sort (Edge<WeightT> *edges, DimEdge count) {
std::sort (edges, edges+count, isEdgeInf);
}
template <typename PixelT, typename WeightT>
inline void
WeightBase2<PixelT, WeightT>::copyPixelsBound (PixelT *leafAPTree, const DimImg &minVal, const DimImg &maxVal) const {
for (DimImg i = minVal; i < maxVal; ++i)
leafAPTree[i] = WB::pixels [i];
}
template <typename PixelT, typename WeightT>
inline void
WeightBase2<PixelT, WeightT>::weight2valueBound (PixelT *compAPTree, const WeightT *compWeights,
const DimImg &minVal, const DimImg &maxVal) const {
//memcpy (compAPTree+minVal, compWeights+minVal, maxVal-minVal);
for (DimImg compIdx = minVal; compIdx < maxVal; ++compIdx)
compAPTree[compIdx] = compWeights[compIdx];
}
// ========================================
template <typename PixelT, typename WeightT>
inline bool
MinWeight<PixelT, WeightT>::getDecr () const {
return true;
}
template <typename PixelT, typename WeightT>
inline bool
MinWeight<PixelT, WeightT>::isWeightInf (const WeightT &a, const WeightT &b) {
return a > b;
}
template <typename PixelT, typename WeightT>
inline bool
MinWeight<PixelT, WeightT>::isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b) {
return isWeightInf (a.weight, b.weight);
}
template <typename PixelT, typename WeightT>
inline void
MinWeight<PixelT, WeightT>::sort (Edge<WeightT> *edges, DimEdge count) {
std::sort (edges, edges+count, isEdgeInf);
}
template <typename PixelT, typename WeightT>
inline
MinWeight<PixelT, WeightT>::MinWeight (const PixelT *pixels, const Size &size)
: WB (pixels, size) {
}
template <typename PixelT, typename WeightT>
inline WeightT
MinWeight<PixelT, WeightT>::getWeight (const DimImg &idx) const {
return WB::getValue (idx);
}
template <typename PixelT, typename WeightT>
inline WeightT
MinWeight<PixelT, WeightT>::getWeight (const Point &a, const Point &b) const {
return std::min (getWeight (WB::pointIdx (a)),
getWeight (WB::pointIdx (b)));
}
// ========================================
template <typename PixelT, typename WeightT>
inline
MaxWeight<PixelT, WeightT>::MaxWeight (const PixelT *pixels, const Size &size)
: WB (pixels, size) {
}
template <typename PixelT, typename WeightT>
inline WeightT
MaxWeight<PixelT, WeightT>::getWeight (const DimImg &idx) const {
return WB::getValue (idx);
}
template <typename PixelT, typename WeightT>
inline WeightT
MaxWeight<PixelT, WeightT>::getWeight (const Point &a, const Point &b) const {
return std::max (getWeight (WB::pointIdx (a)),
getWeight (WB::pointIdx (b)));
}
// ========================================
template <typename PixelT, typename WeightT>
inline
DiffWeight<PixelT, WeightT>::DiffWeight (const PixelT *pixels, const Size &size)
: WB (pixels, size) {
}
template <typename PixelT, typename WeightT>
inline WeightT
DiffWeight<PixelT, WeightT>::getWeight (const DimImg &idx) const {
return 0;
}
template <typename PixelT, typename WeightT>
inline WeightT
DiffWeight<PixelT, WeightT>::getWeight (const Point &a, const Point &b) const {
PixelT va = WB::getValue (a), vb = WB::getValue (b);
return std::max (va, vb) - std::min (va, vb);
}
// ========================================
template <typename PixelT, typename WeightT>
inline bool
MedianWeight<PixelT, WeightT>::getDecr () const {
return true;
}
template <typename PixelT, typename WeightT>
inline bool
MedianWeight<PixelT, WeightT>::isWeightInf (const WeightT &a, const WeightT &b) {
return a > b;
}
template <typename PixelT, typename WeightT>
inline bool
MedianWeight<PixelT, WeightT>::isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b) {
return isWeightInf (a.weight, b.weight);
}
template <typename PixelT, typename WeightT>
inline void
MedianWeight<PixelT, WeightT>::sort (Edge<WeightT> *edges, DimEdge count) {
std::sort (edges, edges+count, isEdgeInf);
}
template <typename PixelT, typename WeightT>
inline const PixelT &
MedianWeight<PixelT, WeightT>::getMedian () const {
return median;
}
template <typename PixelT, typename WeightT>
inline const PixelT &
MedianWeight<PixelT, WeightT>::getThresholdPixel () const {
return thresholdPixel;
}
template <typename PixelT, typename WeightT>
inline const WeightT &
MedianWeight<PixelT, WeightT>::getThresholdWeight () const {
return thresholdWeight;
}
template <typename PixelT, typename WeightT>
inline WeightT
MedianWeight<PixelT, WeightT>::value2weight (const PixelT &val) const {
if (median < WB::halfPixel) {
if (val >= thresholdPixel)
return val;
return val < median ? (median-val)*2 - 1 : (val-median)*2;
}
if (val < thresholdPixel)
return WB::maxPixel - val;
return val < median ? (median-val)*2 - 1 : (val-median)*2;
}
template <typename PixelT, typename WeightT>
inline PixelT
MedianWeight<PixelT, WeightT>::weight2value (const WeightT &weight) const {
if (median < WB::halfPixel) {
if (weight >= thresholdWeight)
return weight;
return int (weight) % 2 ? median - 1 - weight/2 : median + weight/2;
}
if (weight > thresholdWeight)
return WB::maxPixel - weight;
return int (weight) % 2 ? median - weight/2 : median + weight/2;
}
template <typename PixelT, typename WeightT>
inline WeightT
MedianWeight<PixelT, WeightT>::getWeight (const DimImg &idx) const {
return value2weight (WB::getValue (idx));
}
template <typename PixelT, typename WeightT>
inline WeightT
MedianWeight<PixelT, WeightT>::getWeight (const Point &a, const Point &b) const {
return std::min (getWeight (WB::pointIdx (a)),
getWeight (WB::pointIdx (b)));
}
template <typename PixelT, typename WeightT>
inline void
MedianWeight<PixelT, WeightT>::weight2valueBound (PixelT *compAPTree, const WeightT *compWeights,
const DimImg &minVal, const DimImg &maxVal) const {
for (DimImg compIdx = minVal; compIdx < maxVal; ++compIdx)
compAPTree[compIdx] = weight2value (compWeights[compIdx]);
}
// ========================================
template <typename PixelT, typename WeightT>
inline
MedianWeight<PixelT, WeightT>::MedianWeight (const PixelT *pixels, const GraphWalker &graphWalker)
: WB (pixels, graphWalker.size) {
median = graphWalker.getMedian<WeightT> (*this);
thresholdPixel = median < WB::halfPixel ? median * 2 : WB::maxPixel - (WB::maxPixel-median) * 2;
thresholdWeight = median < WB::halfPixel ? median * 2 : (WB::maxPixel-median) * 2;
}
// ========================================
#endif // _OTB_TRISKELE_ARRAY_TREE_WEIGHT_TPP