当前位置: 首页>>代码示例>>C++>>正文


C++ Octree::isLeaf方法代码示例

本文整理汇总了C++中Octree::isLeaf方法的典型用法代码示例。如果您正苦于以下问题:C++ Octree::isLeaf方法的具体用法?C++ Octree::isLeaf怎么用?C++ Octree::isLeaf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Octree的用法示例。


在下文中一共展示了Octree::isLeaf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:aigamedev,项目名称:mapcrafter,代码行数:56,代码来源:quantization.cpp

示例2: testOctreeWithImage

void testOctreeWithImage(const RGBAImage& image) {
	std::set<RGBAPixel> colors;
	int r = 0, g = 0, b = 0, count = 0;

	Octree octree;

	// insert all pixels into an octree
	for (int x = 0; x < image.getWidth(); x++) {
		for (int y = 0; y < image.getHeight(); y++) {
			RGBAPixel color = image.getPixel(x, y);
			colors.insert(color);
			r += rgba_red(color);
			g += rgba_green(color);
			b += rgba_blue(color);
			count++;

			Octree::findOrCreateNode(&octree, color)->setColor(color);
		}
	}

	// make sure that all colors are inserted correctly
	BOOST_CHECK(octree.isRoot() && !octree.isLeaf());
	BOOST_CHECK(!octree.hasColor());

	// reduce all colors up to the root of the tree
	// the color should be the overall average color
	traverseReduceOctree(&octree);
	BOOST_CHECK(octree.hasColor());

	RGBAPixel average1 = octree.getColor();
	RGBAPixel average2 = rgba(r / count, g / count, b / count, 255);
	BOOST_CHECK_EQUAL(average1, average2);

	BOOST_TEST_MESSAGE("Overall colors: " << colors.size());
	BOOST_TEST_MESSAGE("Pixels per color: " << (double) (image.getWidth() * image.getHeight()) / colors.size());
	BOOST_TEST_MESSAGE("Average color: " << (int) rgba_red(average1) << ","
			<< (int) rgba_green(average1) << "," << (int) rgba_blue(average1));
}
开发者ID:corefan,项目名称:mapcrafter,代码行数:38,代码来源:test_image_quantization.cpp

示例3: RayCast

    MeshComponent* OctreeSpatialPartitions::RayCast(Ray ray, float* outDistance)
    {
        ScopedLock _lock(octree.elementsLock);

        if (filterDuplicates)
            lastRaycastBucket = nullptr;
        
        Octree* currentLeaf = &octree;
        float dist = 0;
        Vector<3> point = ray.origin;

        MeshComponent* result = nullptr;
        float distance = 0;

        while (true)
        {
            if (currentLeaf == nullptr)
                break;

            point = ray.origin + ray.direction * dist;
            while (!currentLeaf->isLeaf())
            {
                currentLeaf = currentLeaf->child(point[0] > currentLeaf->centerX(), point[1] > currentLeaf->centerY(), point[2] > currentLeaf->centerZ());
            }

            float xDist = (ray.direction[0] < 0 ? currentLeaf->minX() : currentLeaf->maxX()) - point[0];
            float yDist = (ray.direction[1] < 0 ? currentLeaf->minY() : currentLeaf->maxY()) - point[1];
            float zDist = (ray.direction[2] < 0 ? currentLeaf->minZ() : currentLeaf->maxZ()) - point[2];

            float xNext = dist + xDist / ray.direction[0];
            float yNext = dist + yDist / ray.direction[1];
            float zNext = dist + zDist / ray.direction[2];

            float currentDistance;
            MeshComponent* currentResult = RayCastPartition(currentLeaf, ray, &currentDistance);
            if (currentResult != nullptr)
            {
                if (aggressiveShortCircuit)
                {
                    result = currentResult;
                    distance = currentDistance;
                    break;
                }
                else
                {
                    if (result == nullptr || currentDistance < distance)
                    {
                        result = currentResult;
                        distance = currentDistance;
                    }
                }
            }

            if (!aggressiveShortCircuit && result != nullptr && distance < xNext && distance < yNext && distance < zNext)
            {
                break;
            }

            if (xNext < yNext)
            {
                if (xNext < zNext)
                {
                    dist = xNext;
                    currentLeaf = currentLeaf->neighborX(ray.direction[0] > 0);
                    continue;
                }
            }
            else if (yNext < zNext)
            {
                dist = yNext;
                currentLeaf = currentLeaf->neighborY(ray.direction[1] > 0);
                continue;
            }
            dist = zNext;
            currentLeaf = currentLeaf->neighborZ(ray.direction[2] > 0);
        }
        
        if (result != nullptr)
            *outDistance = distance;
        return result;
    }
开发者ID:aboveyou00,项目名称:GL-VR-Engine,代码行数:81,代码来源:OctreeSpatialPartitions.cpp


注:本文中的Octree::isLeaf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。