triskele/include/ArrayTree/Weight.hpp
Git Merciol e097095f3b nouveau fichier : include/ArrayTree/ArrayTreeBuilder.hpp
nouveau fichier : include/ArrayTree/ArrayTreeBuilder.tpp
	nouveau fichier : include/ArrayTree/Border.hpp
	nouveau fichier : include/ArrayTree/GraphWalker.hpp
	nouveau fichier : include/ArrayTree/Leader.hpp
	nouveau fichier : include/ArrayTree/Weight.hpp
	nouveau fichier : include/ArrayTree/Weight.tpp
	nouveau fichier : include/ArrayTree/triskeleArrayTreeBase.hpp
	nouveau fichier : include/ArrayTree/triskeleSort.hpp
	nouveau fichier : include/ArrayTree/triskeleSort.tpp
	modifié :         include/Attribute.hpp
	modifié :         include/Attributes/AreaAttribute.hpp
	supprimé :        include/BuildTree.hpp
	supprimé :        include/DAPTree/Border.hpp
	supprimé :        include/DAPTree/DAPTreeBuilder.hpp
	supprimé :        include/DAPTree/DAPTreeBuilder.tpp
	supprimé :        include/DAPTree/GraphWalker.hpp
	supprimé :        include/DAPTree/ParRnk.hpp
	supprimé :        include/DAPTree/Weight.hpp
	supprimé :        include/DAPTree/baseDAPTree.hpp
	supprimé :        include/DAPTree/sort.hpp
	nouveau fichier : include/IImage.hpp
	nouveau fichier : include/IImage.tpp
	supprimé :        include/ImageInterface.hpp
	supprimé :        include/ImageInterface.tpp
	modifié :         include/QuadTree/QuadTreeBuilder.hpp
	modifié :         include/Tree.hpp
	nouveau fichier : include/TreeBuilder.hpp
	supprimé :        include/TreeOfShapesGeraud/ToSBuilder.hpp
	supprimé :        include/TreeOfShapesGeraud/ToSutils.hpp
	modifié :         include/XMLTree/XMLTreeBuilder.hpp
	supprimé :        include/baseDef.hpp
	supprimé :        include/getType.hpp
	nouveau fichier : include/triskeleBase.hpp
	renommé :         include/dealThreads.hpp -> include/triskeleDealThreads.hpp
	nouveau fichier : include/triskeleDealThreads.tpp
	renommé :         include/debug.hpp -> include/triskeleDebug.hpp
	nouveau fichier : include/triskeleGdalGetType.hpp
	modifié :         otb-module.cmake
	nouveau fichier : src/ArrayTree/triskeleArrayTreeBase.cpp
	modifié :         src/Attribute.cpp
	modifié :         src/Attributes/AreaAttribute.cpp
	modifié :         src/CMakeLists.txt
	supprimé :        src/DAPTree/GraphWalker.cpp
	supprimé :        src/DAPTree/ParRnk.cpp
	supprimé :        src/DAPTree/baseDAPTree.cpp
	supprimé :        src/DAPTree/sort.cpp
	modifié :         src/QuadTree/QuadTreeBuilder.cpp
	modifié :         src/Tree.cpp
	supprimé :        src/TreeOfShapesGeraud/ToSBuilder.cpp
	supprimé :        src/TreeOfShapesGeraud/ToSutils.cpp
	modifié :         src/XMLTree/XMLTreeBuilder.cpp
	supprimé :        src/debug.cpp
	modifié :         src/testMain.cpp
	nouveau fichier : src/triskeleDebug.cpp
	supprimé :        tests/ToSGeraudCoord.txt
	supprimé :        tests/ToSGeraudIdx.ods
2017-11-26 18:38:11 +01:00

176 lines
6.8 KiB
C++

#ifndef _OTB_TRISKELE_ARRAY_TREE_WEIGHT_HPP
#define _OTB_TRISKELE_ARRAY_TREE_WEIGHT_HPP
#include <iostream>
#include <typeinfo>
#include "triskeleBase.hpp"
#include "triskeleArrayTreeBase.hpp"
namespace otb {
namespace triskele {
namespace arrayTree {
class GraphWalker;
/*! Structure définissant la base d'un poids entre les pixels */
template <typename PixelT> struct WeightBase {
protected:
const PixelT *pixels;
const Size size;
DimNodeId pointIdx (const Point &p) const { return point2idx (size, p); }
PixelT halfPixel, maxPixel;
public:
const Size &getSize () const { return size; }
const PixelT &getValue (const DimImg &idx) const { return pixels[idx]; }
const PixelT &getValue (const Point &p) const { return getValue (pointIdx (p)); }
bool getDecr () const { return false; }
const PixelT &getMaxPixel () const { return maxPixel; }
const PixelT &getHalfPixel () const { return halfPixel; }
PixelT *allocAP (const DimNodeId &nodeCapacity) const { return new PixelT [nodeCapacity]; }
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> struct WeightBase2 : public WeightBase<PixelT> {
typedef WeightBase<PixelT> WB;
WeightBase2 (const PixelT *pixels, const Size &size)
: WB (pixels, size) {}
static bool isWeightInf (const WeightT &a, const WeightT &b) { return a < b; }
static bool isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b) { return isWeightInf (a.weight, b.weight); }
static void sort (Edge<WeightT> *edges, DimEdge count) { std::sort (edges, edges+count, isEdgeInf); }
void copyPixelsBound (PixelT *leafAPTree,
const DimImg &minVal, const DimImg &maxVal) const {
for (DimImg i = minVal; i < maxVal; ++i)
leafAPTree[i] = WB::pixels [i];
}
void 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];
}
};
/*! Structure intégrant la façon dont est géré un poids pour un MinTree */
template <typename PixelT, typename WeightT> struct MinWeight : public WeightBase2<PixelT, WeightT> {
typedef WeightBase2<PixelT, WeightT> WB;
bool getDecr () const { return true; }
static bool isWeightInf (const WeightT &a, const WeightT &b) { return a > b; }
static bool isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b) { return isWeightInf (a.weight, b.weight); }
static void sort (Edge<WeightT> *edges, DimEdge count) { std::sort (edges, edges+count, isEdgeInf); }
MinWeight (const PixelT *pixels, const Size &size)
: WB (pixels, size) {}
WeightT getWeight (const DimImg &idx) const { return WB::getValue (idx); }
WeightT getWeight (const Point &a, const Point &b) const { return std::min (getWeight (WB::pointIdx (a)),
getWeight (WB::pointIdx (b))); }
};
// ========================================
/*! Structure intégrant la façon dont est géré un poids pour un MaxTree */
template <typename PixelT, typename WeightT> struct MaxWeight : public WeightBase2<PixelT, WeightT> {
typedef WeightBase2<PixelT, WeightT> WB;
MaxWeight (const PixelT *pixels, const Size &size)
: WB (pixels, size) {}
WeightT getWeight (const DimImg &idx) const { return WB::getValue (idx); }
WeightT getWeight (const Point &a, const Point &b) const { return std::max (getWeight (WB::pointIdx (a)),
getWeight (WB::pointIdx (b))); }
};
// ========================================
/*! Structure intégrant la façon dont est géré un poids pour un AlphaTree */
template <typename PixelT, typename WeightT> struct DiffWeight : public WeightBase2<PixelT, WeightT> {
typedef WeightBase2<PixelT, WeightT> WB;
DiffWeight (const PixelT *pixels, const Size &size)
: WB (pixels, size) {}
WeightT getWeight (const DimImg &idx) const { return 0; }
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);
}
};
// ========================================
/*! Structure intégrant la façon dont est géré un poids pour un TreeOfShape */
template <typename PixelT, typename WeightT> struct MedianWeight : public WeightBase2<PixelT, WeightT> {
typedef WeightBase2<PixelT, WeightT> WB;
protected:
PixelT median, thresholdPixel;
WeightT thresholdWeight;
public:
bool getDecr () const { return true; }
static bool isWeightInf (const WeightT &a, const WeightT &b) { return a > b; }
static bool isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b) { return isWeightInf (a.weight, b.weight); }
static void sort (Edge<WeightT> *edges, DimEdge count) { std::sort (edges, edges+count, isEdgeInf); }
const PixelT &getMedian () const { return median; }
const PixelT &getThresholdPixel () const { return thresholdPixel; }
const WeightT &getThresholdWeight () const { return thresholdWeight; }
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;
}
PixelT 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;
}
inline MedianWeight (const PixelT *pixels, const GraphWalker &graphWalker);
WeightT getWeight (const DimImg &idx) const { return value2weight (WB::getValue (idx)); }
WeightT getWeight (const Point &a, const Point &b) const { return std::min (getWeight (WB::pointIdx (a)),
getWeight (WB::pointIdx (b))); }
void 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]);
}
};
} // arrayTree
} // triskele
} // otb
#include "GraphWalker.hpp"
namespace otb {
namespace triskele {
namespace arrayTree {
#include "Weight.tpp"
} // arrayTree
} // triskele
} // otb
#endif // _OTB_TRISKELE_ARRAY_TREE_WEIGHT_HPP