#include "Tree.hpp" using namespace otb::triskele; using namespace std; Tree::Tree (const DimSideImg &width, const DimSideImg &height, unsigned int coreCount) : Tree (coreCount) { resize (width, height); } Tree::Tree (unsigned int coreCount) : size (), coreCount (coreCount), leafCount (0), nodeCount (0), leafParents (nullptr), compParents (nullptr), children (nullptr), childCount (nullptr), state (State::Void) { clear (); } Tree::~Tree () { free (); } void Tree::clear () { nodeCount = leafCount; if (!leafCount) return; childCount[0] = childCount[1] = 0; // XXX dealThreadFill_n avec coreCount fill_n (leafParents, leafCount*2, DimImg_MAX); #ifdef SMART_LOG fill_n (children, (leafCount-1)*2, 0); fill_n (childCount, leafCount+1, 0); #endif weightBounds.resize (0); } void Tree::resize (const DimSideImg &width, const DimSideImg &height) { size = Size (width, height); book ((DimImg)width * (DimImg)height); clear (); } void Tree::free () { if (leafParents) delete[] leafParents; leafParents = compParents = nullptr; if (children) delete[] children; if (childCount) delete[] childCount; children = childCount = nullptr; weightBounds.resize (0); } void Tree::book (const DimImg &leafCount) { if (this->leafCount == leafCount) { clear (); return; } free (); if (!leafCount) return; this->leafCount = leafCount; leafParents = new DimNodeId[leafCount*2]; compParents = leafParents + leafCount; children = new DimNodeId[(leafCount-1)*2]; childCount = new DimNodeId[leafCount+2]; clear (); } #ifdef ENABLE_LOG void Tree::printTree () const { cout << "tree parent count children" << endl; Size doubleSize (size.width, 2*size.height); printMap (cout, leafParents, doubleSize, nodeCount) << endl << endl; printMap (cout, childCount, size, ((DimNodeId) getCompCount ()) + 1) << endl << endl; printMap (cout, children, doubleSize, nodeCount) << endl << endl; } #endif