triskele/include/CompAttribute.tpp
Git Merciol aff93d5467 modifié : include/Appli/Option.hpp
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/triskeleDealThreads.tpp
	modifié :         src/Appli/Option.cpp
	modifié :         src/IImage.cpp
	modifié :         src/apGenerator.cpp
2018-04-20 09:49:46 +02:00

175 lines
5.7 KiB
C++

#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
#define _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
// ========================================
template<typename AttrT>
inline vector<AttrT>
CompAttribute<AttrT>::getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue) {
vector<AttrT> result;
for (double percent : thresholds)
result.push_back (percent*maxValue);
return result;
}
template<typename AttrT>
inline vector<AttrT>
CompAttribute<AttrT>::getConvertedThresholds (const vector<double> &thresholds) {
vector<AttrT> result;
for (double value : thresholds)
result.push_back ((AttrT) value);
return result;
}
// ========================================
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>
template<typename PixelT>
inline void
CompAttribute<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
DEF_LOG ("CompAttribute::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
CompAttribute<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 << "CompAttribute::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];
}
}
// ========================================
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;
return out;
}
// ========================================
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>
template<typename CumpFunctPSE>
inline void
CompAttribute<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
DEF_LOG ("CompAttribute::computeSameCompLevel", "coreCount:" << coreCount);
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
LOG ("CompAttribute::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;
}
}
// ========================================
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP