triskele/include/CompAttribute.tpp
Git Merciol 8ca10923c4 modifié : include/ArrayTree/ArrayTreeBuilder.hpp
modifié :         include/ArrayTree/ArrayTreeBuilder.tpp
	modifié :         include/ArrayTree/Border.hpp
	modifié :         include/ArrayTree/Border.tpp
	modifié :         include/ArrayTree/GraphWalker.tpp
	modifié :         include/ArrayTree/Leader.hpp
	modifié :         include/ArrayTree/Leader.tpp
	modifié :         include/Attribute.hpp
	modifié :         include/AttributeProfiles.hpp
	modifié :         include/AttributeProfiles.tpp
	modifié :         include/CompAttribute.hpp
	modifié :         include/CompAttribute.tpp
	modifié :         include/IImage.hpp
	modifié :         include/IImage.tpp
	modifié :         include/Tree.hpp
	modifié :         include/Tree.tpp
	modifié :         include/TreeBuilder.hpp
	modifié :         include/TreeBuilder.tpp
	supprimé :        src/Attribute.cpp
	modifié :         src/CMakeLists.txt
	modifié :         src/QuadTree/QuadTreeBuilder.cpp
	modifié :         src/TestArrayTreeBuilder.cpp
	modifié :         src/Tree.cpp
	modifié :         src/XMLTree/XMLTreeBuilder.cpp
	modifié :         src/apGenerator.cpp
2018-03-06 21:57:15 +01:00

171 lines
5.4 KiB
C++

#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
#define _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
template<typename AttrT>
inline
CompAttribute<AttrT>::CompAttribute (const Tree &tree)
: tree (tree),
leafCount (0),
values () {
updateTranscient ();
}
template<typename AttrT>
inline
CompAttribute<AttrT>::~CompAttribute () {
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::updateTranscient () {
// XXX max : leafCount-1
book (tree.getLeafCount ());
}
template<typename AttrT>
inline const AttrT *
CompAttribute<AttrT>::getValues () const {
return &values[0];
}
template<typename AttrT>
inline AttrT *
CompAttribute<AttrT>::getValues () {
return &values[0];
}
template<typename AttrT>
inline AttrT
CompAttribute<AttrT>::getMaxValue () const {
if (!leafCount)
return 0;
AttrT max = values[0];
CompAttribute<AttrT>::tree.forEachComp ([this, &max] (const DimImg &compId) {
if (values[compId] > max)
max = values[compId];
});
return max;
}
template<typename AttrT>
inline ostream &
CompAttribute<AttrT>::print (ostream &out, const string &msg) const {
cout << "values: " << msg << endl;
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
cout << printMap (&values[0], doubleSize, tree.getCompCount ()) << endl << endl;
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::free () {
values = vector<AttrT> ();
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::book (const DimImg &leafCount) {
this->leafCount = leafCount;
values.resize (leafCount);
}
// ========================================
template<typename AttrT>
inline
CompAttributeC<AttrT>::CompAttributeC (const Tree &tree)
: CompAttribute<AttrT> (tree) {
}
template<typename AttrT>
inline
CompAttributeC<AttrT>::~CompAttributeC () {
}
template<typename AttrT>
inline vector<AttrT>
CompAttributeC<AttrT>::getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue) {
vector<AttrT> result;
for (AttrT percent : thresholds)
result.push_back (percent*maxValue);
return result;
}
template<typename AttrT>
template<typename CumpFunctPSE>
inline void
CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
DEF_LOG ("CompAttributeC::computeSameCompLevel", "coreCount:" << coreCount);
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
LOG ("CompAttributeC::computeSameCompLevel: no thread");
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
return;
}
DimImg first = weightBounds [0];
for (DimImg curBound = 1; curBound < weightBounds.size (); curBound++) {
DimImg next = weightBounds [curBound];
dealThreadRange (next-first, coreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
const DimImg parentId = id+first;
cumpFunctPSE (parentId);
});
first = next;
}
}
template<typename AttrT>
template<typename PixelT>
inline void
CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
DEF_LOG ("CompAttributeC::cut", "coreCount:" << CompAttribute<AttrT>::tree.getCoreCount () << " thresholds:" << thresholds.size ());
dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::tree.getCoreCount (), [this, &allBands, &attributeProfiles, &pixelAttrValue, &thresholds] (const DimImg &leafId) {
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, thresholds);
});
}
template<typename AttrT>
template<typename PixelT>
inline void
CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const DimImg &leafId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
// no debug (to many pixels)
DimImg parentId = CompAttribute<AttrT>::tree.getLeafParent (leafId);
DimChanel thresholdsSize = thresholds.size ();
if (parentId == DimImg_MAX) {
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel)
allBands[chanel][leafId] = 0;
return;
}
DimNodeId nodeId = leafId;
DimImg curId = 0;
AttrT curValue = pixelAttrValue;
if (curValue == CompAttribute<AttrT>::values [parentId]) {
// skip pixel on flat zone
curId = parentId;
nodeId = ((DimNodeId)curId)+CompAttribute<AttrT>::leafCount;
parentId = CompAttribute<AttrT>::tree.getCompParent (curId);
}
const PixelT *apValues = attributeProfiles.getValues ();
DimImg rootId = CompAttribute<AttrT>::tree.getCompRoot ();
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel) {
AttrT ceil = thresholds[chanel];
for ( ; curValue < ceil && curId < rootId; ) {
if (parentId == DimImg_MAX || curId >= parentId) {
// cerr << "CompAttributeC::cutOnPos find sub-root:" << rootId << " rootId:" << rootId << endl;
for (; chanel < thresholdsSize; ++chanel)
allBands[chanel][leafId] = curValue;
return;
}
nodeId = ((DimNodeId) CompAttribute<AttrT>::tree.getLeafParent (nodeId))+CompAttribute<AttrT>::leafCount;
curId = parentId;
curValue = CompAttribute<AttrT>::values [curId];
parentId = CompAttribute<AttrT>::tree.getCompParent (curId);
}
// XXX si valeur > root ?
allBands[chanel][leafId] = apValues [nodeId];
}
}
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP