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


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

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


在下文中一共展示了Octree::Build方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TestOctree

void TestOctree()
{
	std::vector<vgl_point_3d<double> > Points;
	Points.push_back(vgl_point_3d<double>(1.0, 0.0, 0.0));
	Points.push_back(vgl_point_3d<double>(0.0, 0.0, 0.0));
	Points.push_back(vgl_point_3d<double>(0.0, 1.0, 0.0));
	
	std::vector<std::vector<unsigned int> > VertexLists;
	std::vector<unsigned int> VertexList;
	VertexList.push_back(0);
	VertexList.push_back(1);
	VertexList.push_back(2);
	VertexLists.push_back(VertexList);
	
	Octree Tree;
	Tree.Build(Points, VertexLists);
	
	OrientedPoint Intersection;
	Ray R(vgl_point_3d<double>(0.5, 0.5, -1.0), vgl_vector_3d<double> (0.0, 0.0, 1.0));
	bool intersect = Tree.IntersectRay(R, Intersection);
	
	std::cout << "Intersect? " << intersect << std::endl;
	if(intersect)
		std::cout << "Intersection: " << Intersection << std::endl;
}
开发者ID:daviddoria,项目名称:Tools,代码行数:25,代码来源:TestOctree.cpp

示例2: Process

void Processor::Process(void)
{
	for (int n = 0 ; n < 1 && this->ProcessFrame() ; ++n)
	{
		std::cout << "Computing visible voxels..." << std::endl;

		// Update the visible voxels
		this->m_Reconstructor.Update();

		std::cout << "Computed visible voxels" << std::endl;

		const unsigned int numVisibleVoxels = this->m_Reconstructor.GetNumVisibleVoxels();
		VisibleVoxel* visibleVoxels = this->m_Reconstructor.GetVisibleVoxels();

		std::cout << "Number of visible voxels: " << numVisibleVoxels << std::endl;
		std::cout << "Memory usage: " << (numVisibleVoxels * sizeof(VisibleVoxel)) / 1000000 << "MB" << std::endl;

		std::cout << "Determining boundaries..." << std::endl;

		// Find bounds
		glm::vec3 min = {0.0f, 0.0f, 0.0f};
		glm::vec3 max = {0.0f, 0.0f, 0.0f};
		glm::vec3 cellSize = {1.0f, 1.0f, 1.0f};
		for (int i = 0 ; i < numVisibleVoxels ; ++i)
		{
			VisibleVoxel &v = visibleVoxels[i];

			min[0] = v.X < min[0] ? v.X : min[0]; max[0] = v.X > max[0] ? v.X : max[0];
			min[1] = v.X < min[1] ? v.X : min[1]; max[1] = v.X > max[1] ? v.X : max[1];
			min[2] = v.X < min[2] ? v.X : min[2]; max[2] = v.X > max[2] ? v.X : max[2];
		}

		std::cout << "Boundaries are: (" << min[0] << ", " << min[1] << ", " << min[2] << ") -> (" << max[0] << ", " << max[1] << ", " << max[2] << ")" << std::endl;

		std::cout << "Adding voxels to octree..." << std::endl;

		Octree *octree = new Octree(glm::vec3(0, 0, 0), max);
		octree->SetVoxels(visibleVoxels);
		octree->SetNumVoxels(numVisibleVoxels);

		std::cout << "Building octree..." << std::endl;

		std::chrono::system_clock::time_point start = std::chrono::high_resolution_clock::now();
		octree->Build();
		std::chrono::duration<float> b = std::chrono::system_clock::now().time_since_epoch();
		std::chrono::system_clock::time_point end = std::chrono::high_resolution_clock::now();
		std::chrono::duration<double> diff = end - start;
		std::cout << "Spent " << diff.count() * 1000 << " milliseconds" << std::endl;

		std::cout << "Number of nodes: " << octree->GetNumNodes() << std::endl;
		std::cout << "Memory usage: " << float(octree->GetNumNodes() * sizeof(OctreeNode)) / 1000000 << "MB" << std::endl;

		std::cout << "Compressing..." << std::endl;
		this->m_Compressor->Compress(octree);

		delete octree;
		
		std::cout << "Done, next frame!" << std::endl;
	}

	std::cout << "Done processing!" << std::endl;
}
开发者ID:ofx,项目名称:Cuda-3d-reconstruction,代码行数:62,代码来源:Processor.cpp

示例3: BuildVertexAmbientOcclusion

void AmbientOcclusionApp::BuildVertexAmbientOcclusion(
	std::vector<Vertex::AmbientOcclusion>& vertices,
	const std::vector<UINT>& indices)
{
	UINT vcount = vertices.size();
	UINT tcount = indices.size()/3;

	std::vector<XMFLOAT3> positions(vcount);
	for(UINT i = 0; i < vcount; ++i)
		positions[i] = vertices[i].Pos;

	Octree octree;
	octree.Build(positions, indices);

	// For each vertex, count how many triangles contain the vertex.
	std::vector<int> vertexSharedCount(vcount);
	for(UINT i = 0; i < tcount; ++i)
	{
		UINT i0 = indices[i*3+0];
		UINT i1 = indices[i*3+1];
		UINT i2 = indices[i*3+2];

		XMVECTOR v0 = XMLoadFloat3(&vertices[i0].Pos);
		XMVECTOR v1 = XMLoadFloat3(&vertices[i1].Pos);
		XMVECTOR v2 = XMLoadFloat3(&vertices[i2].Pos);

		XMVECTOR edge0 = v1 - v0;
		XMVECTOR edge1 = v2 - v0;

		XMVECTOR normal = XMVector3Normalize(XMVector3Cross(edge0, edge1));

		XMVECTOR centroid = (v0 + v1 + v2)/3.0f;

		// Offset to avoid self intersection.
		centroid += 0.001f*normal;

		const int NumSampleRays = 32;
		float numUnoccluded = 0;
		for(int j = 0; j < NumSampleRays; ++j)
		{
			XMVECTOR randomDir = MathHelper::RandHemisphereUnitVec3(normal);

			// TODO: Technically we should not count intersections that are far 
			// away as occluding the triangle, but this is OK for demo.
			if( !octree.RayOctreeIntersect(centroid, randomDir) )
			{
				numUnoccluded++;
			}
		}
		
		float ambientAccess = numUnoccluded / NumSampleRays;

		// Average with vertices that share this face.
		vertices[i0].AmbientAccess += ambientAccess;
		vertices[i1].AmbientAccess += ambientAccess;
		vertices[i2].AmbientAccess += ambientAccess;

		vertexSharedCount[i0]++;
		vertexSharedCount[i1]++;
		vertexSharedCount[i2]++;
	}

	// Finish average by dividing by the number of samples we added.
	for(UINT i = 0; i < vcount; ++i)
	{
		vertices[i].AmbientAccess /= vertexSharedCount[i];
	}
}
开发者ID:Santhura,项目名称:Advanced-graphics-programming-,代码行数:68,代码来源:AmbientOcclusionDemo.cpp


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