本文整理汇总了C++中Octree::reduceToParent方法的典型用法代码示例。如果您正苦于以下问题:C++ Octree::reduceToParent方法的具体用法?C++ Octree::reduceToParent怎么用?C++ Octree::reduceToParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Octree
的用法示例。
在下文中一共展示了Octree::reduceToParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: octreeColorQuantize
/**
* Simple octree color quantization: Similar to http://rosettacode.org/wiki/Color_quantization#C
*/
void octreeColorQuantize(const RGBAImage& image, size_t max_colors,
std::vector<RGBAPixel>& colors, Octree** octree) {
assert(max_colors > 0);
// have an octree with the colors as leaves
Octree* internal_octree = new Octree();
// and a priority queue of leaves to be processed
// the order of leaves is very important, see NodeComparator
std::priority_queue<Octree*, std::vector<Octree*>, NodeComparator> queue;
// insert the colors into the octree
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
RGBAPixel color = image.pixel(x, y);
Octree* node = Octree::findOrCreateNode(internal_octree, color);
node->setColor(color);
// add the leaf only once to the queue
if (node->getCount() == 1)
queue.push(node);
}
}
// now: reduce the leaves until we have less colors than maximum
while (queue.size() > max_colors) {
Octree* node = queue.top();
assert(node->isLeaf());
queue.pop();
// add the color value of the leaf to the parent
node->reduceToParent();
Octree* parent = node->getParent();
// delete the leaf (leaf is automatically removed from parent in reduceToParent())
delete node;
// add parent to queue if it is a leaf now
if (parent->isLeaf())
queue.push(parent);
}
// gather the quantized colors
while (queue.size()) {
Octree* node = queue.top();
assert(node->isLeaf());
node->setColorID(colors.size());
colors.push_back(node->getColor());
queue.pop();
}
if (octree != nullptr)
*octree = internal_octree;
else
delete internal_octree;
}