#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP #define _OTB_TRISKELE_COMP_ATTRIBUTE_TPP template inline CompAttribute::CompAttribute (const Tree &tree) : tree (tree), leafCount (0), values (nullptr) { updateTranscient (); } template inline CompAttribute::~CompAttribute () { free (); } template inline void CompAttribute::updateTranscient () { book (tree.getLeafCount ()); } template inline const AttrT * CompAttribute::getValues () const { return values; } template inline AttrT * CompAttribute::getValues () { return values; } template inline void CompAttribute::printValues (const string &msg) const { cout << "values: " << msg << endl; const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height); printMap (cout, values, doubleSize, tree.getCompCount ()) << endl << endl; } template inline void CompAttribute::free () { if (values) delete[] values; values = nullptr; } template inline void CompAttribute::book (const DimImg &leafCount) { if (this->leafCount == leafCount) return; free (); if (!leafCount) return; this->leafCount = leafCount; values = new AttrT[leafCount]; } // ======================================== template inline CompAttributeC::CompAttributeC (const Tree &tree) : CompAttribute (tree) { } template inline CompAttributeC::~CompAttributeC () { } template template inline void CompAttributeC::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) { const vector &weightBounds (CompAttribute::tree.getWeightBounds ()); unsigned int coreCount = CompAttribute::tree.getCoreCount (); if (!weightBounds.size () || CompAttribute::tree.getCompCount ()/weightBounds.size () < coreCount) { CompAttribute::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 template inline void CompAttributeC::cut (vector > allBands, const AttributeProfiles &attributeProfiles, const AttrT &pixelAttrValue, const vector > &selection) { dealThreadRange (CompAttribute::leafCount, CompAttribute::coreCount, [this, &allBands, &attributeProfiles, &pixelAttrValue, &selection] (const DimImg &leafId) { cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, selection); }); } template template inline void CompAttributeC::cutOnPos (vector > allBands, const AttributeProfiles &attributeProfiles, const DimImg &leafId, const AttrT &pixelAttrValue, const vector > &selection) { // no debug (to many pixels) DimImg parentId = CompAttribute::tree.getLeafParents (leafId); DimChanel selectionSize = selection.size (); if (parentId == DimImg_MAX) { for (DimChanel i = 0; i < selectionSize; ++i) allBands[leafId][selection[i].chanel] = 0; return; } DimNodeId nodeId = leafId, curId = 0; AttrT curValue = pixelAttrValue; if (curValue == CompAttribute::values [parentId]) { // skip pixel on flat zone curId = parentId; nodeId = curId+CompAttribute::leafCount; parentId = CompAttribute::tree.getCompParent (curId); } DimImg rootId = CompAttribute::tree.getCompRoot (); for (DimChanel i = 0; i < selectionSize; ++i) { AttrT ceil = selection[i].threshold; for ( ; curValue < ceil && curId < rootId; ) { if (parentId == DimImg_MAX || curId >= parentId) { // XXX root for (; i < selectionSize; ++i) allBands[leafId][selection[i].chanel] = 0; return; } nodeId = CompAttribute::tree.getLeafParents (nodeId)+CompAttribute::leafCount; curId = parentId; curValue = CompAttribute::values [curId]; parentId = CompAttribute::tree.getCompParents (curId); } // XXX si valeur > root ? allBands[leafId][selection[i].chanel] = attributeProfiles [nodeId]; } } #endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP