UE4 四叉树 QuadTree
UE4 四叉树 QuadTree
Engine\Source\Runtime\Engine\Public\GenericQuadTree.h
TQuadTree
template <typename ElementType, int32 NodeCapacity = 4>
class TQuadTree
{typedef TQuadTree<ElementType, NodeCapacity> TreeType;
public:/** DO NOT USE. This constructor is for internal usage only for hot-reload purposes. */TQuadTree();TQuadTree(const FBox2D& InBox, float InMinimumQuadSize = 100.f);/** Gets the TreeBox so systems can test insertions before trying to do so with invalid regions */const FBox2D& GetTreeBox() const { return TreeBox; }/** Inserts an object of type ElementType with an associated 2D box of size Box (log n). Pass in a DebugContext so when an issue occurs the log can report what requested this insert. */void Insert(const ElementType& Element, const FBox2D& Box, const TCHAR* DebugContext = nullptr);/** Given a 2D box, returns an array of elements within the box. There will not be any duplicates in the list. */template<typename ElementAllocatorType>void GetElements(const FBox2D& Box, TArray<ElementType, ElementAllocatorType>& ElementsOut) const;/** Removes an object of type ElementType with an associated 2D box of size Box (log n). Does not cleanup tree*/bool Remove(const ElementType& Instance, const FBox2D& Box);/** Does a deep copy of the tree by going through and re-creating the internal data. Cheaper than re-insertion as it should be linear instead of nlogn */void Duplicate(TreeType& OutDuplicate) const;/** Removes all elements of the tree */void Empty();void Serialize(FArchive& Ar);TreeType& operator=(const TreeType& Other);~TQuadTree();private:enum QuadNames{TopLeft = 0,TopRight = 1,BottomLeft = 2,BottomRight = 3};/** Node used to hold the element and its corresponding 2D box*/struct FNode{FBox2D Box;ElementType Element;FNode() {};FNode(const ElementType& InElement, const FBox2D& InBox): Box(InBox), Element(InElement){}friend FArchive& operator<<(FArchive& Ar, typename TQuadTree<ElementType, NodeCapacity>::FNode& Node){return Ar << Node.Box << Node.Element;}};/** Given a 2D box, return the subtrees that are touched. Returns 0 for leaves. */int32 GetQuads(const FBox2D& Box, TreeType* Quads[4]) const;/** Split the tree into 4 sub-trees */void Split();/** Given a list of nodes, return which ones actually intersect the box */template<typename ElementAllocatorType>void GetIntersectingElements(const FBox2D& Box, TArray<ElementType, ElementAllocatorType>& ElementsOut) const;/** Given a list of nodes, remove the node that contains the given element */bool RemoveNodeForElement(const ElementType& Element);/** Internal recursive implementation of @see Insert */void InsertElementRecursive(const ElementType& Element, const FBox2D& Box, const TCHAR* DebugContext);private:/*** Contains the actual elements this tree is responsible for. Nodes are used to keep track of each element's AABB as well.* For a non-internal leaf, this is the list of nodes that are fully contained within this tree.* For an internal tree, this contains the nodes that overlap multiple subtrees.*/TArray<FNode> Nodes;/** The sub-trees of this tree */TreeType* SubTrees[4];/** AABB of the tree */FBox2D TreeBox;/** Center position of the tree */FVector2D Position;/** The smallest size of a quad allowed in the tree */float MinimumQuadSize;/** Whether this is a leaf or an internal sub-tree */bool bInternal;
};
Usage
#include "GenericQuadTree.h"//Setup the Quad tree
float UVsQuadTreeMinSize = 0.001f;
TQuadTree<uint32, 100> QuadTree(BaseMeshUVBound,UVsQuadTreeMinSize);
//Insert data
for (FTriangleElement& TriangleElement : Triangles)
{QuadTree.Insert(TriangleElement.TriangleIndex, TriangleElement.UVsBound, DebugContext);
}
//Find a match triangle for every target vertices
TArray<uint32> QuadTreeTriangleResults;
//Reserve 10% to speed up the query
QuadTreeTriangleResults.Reserve(Triangles.Num() / 10); for (uint32 TargetVertexIndex = 0; TargetVertexIndex < (uint32)TargetVertices.Num(); ++TargetVertexIndex)
{//Reset the last data without flushing the memmery allocationQuadTreeTriangleResults.Reset();FVector2D Extent(DistanceThreshold, DistanceThreshold);FBox2D CurBox(TargetUV - Extent, TargetUV + Extent);while (QuadTreeTriangleResults.Num() <= 0){QuadTree.GetElements(CurBox, QuadTreeTriangleResults);Extent *= 2;CurBox = FBox2D(TargetUV - Extent, TargetUV + Extent);}
}
应用
UE4聚合图测试
参考
- UE4 LOD Screen Size
UE4 四叉树 QuadTree相关推荐
- js小球与边框碰撞反弹_四叉树在碰撞检测中的应用
缘起 <你被追尾了>中预告了加速碰撞检测的算法--四叉树(for 2D),所以本文就来学习一下. 分析 首先是为什么要使用四叉树进行优化,其实<你被追尾了>中已经说了,这里简单 ...
- 两个软件相互交换数据_面试需要知道的六种数据结构
本文作者 拉勾教育专栏作者苏勇查看:13624回复:128 数据结构是算法的基石,若无扎实的数据结构基础,想把算法学好甚至融会贯通是非常困难的,而优秀的算法又往往取决于你采用哪种数据结构. --< ...
- 奥维互动地图GEE协议历史影像分析与应用
Gee协议提供查看Google Earth,Google Maps,Bing Maps,DigitalGlobe,Kosmosnimki,Yandex.Maps等服务提供的高分辨率卫星图像和常规地图. ...
- 数据结构与算法 学习笔记(中)
油管上的CS61B的视频 学习代码 随看随记 Dijkstra's algorithm再理解 Asymptotics 本意是渐近的意思:这里代指当参数为无穷大时,所需要进行运算的次数,和我们常说的复杂 ...
- 《游戏引擎架构》笔记一
<游戏引擎架构>该系列的博文部分参考下面的博客: http://raytaylorlin.com/categories/%E6%8A%80%E6%9C%AF/%E6%B8%B8%E6%88 ...
- 1. 【Part3】 Contour Detection and Hierarchical Image Segmentation【轮廓检测图像分割】
Reference from Arbelaez, P., Maire, M., Fowlkes, C., & Malik, J. (2011). Contour detection and h ...
- Game Engine Architecture by Jason Gregory:1.6 实时游戏引擎架构
http://blog.csdn.net/skylmmm/article/details/6230420 一个游戏引擎一般是由工具集和一个运行时组件组成.下面部分我们将首先研究这个运行时组件,然后再看 ...
- arcmap创建空间索引_空间GIS索引算法介绍
先看几个需要空间索引技术的场景: 如何根据给定位置来查询附近1000米的poi? 如何查找给定位置的最近poi? 如何查找给定矩形框内所有link和面数据? 1.用B-tree.B tree或者has ...
- 学习索引: 现状与研究展望
摘 要: 索引是数据库系统中用于提升数据存取性能的主要技术之一.在大数据时代,随着数据量的不断增长,传 统索引(如 B+树)的问题日益突出:(1)空间代价过高.例如,B+树索引需要借助 O(n)规模的 ...
- 【数据结构Python描述】树的简介、基本概念和手动实现一个二叉树
文章目录 一.树的简介 1. 树的定义 2. 相关概念 二.树的ADT 三.树的实现准备 1. 树的基本分类 2. 树的抽象基类 四.树的概念拾遗 1. 深度 2. 高度 五.二叉树的简介 1. 定义 ...
最新文章
- RStudio启动后修改文件(数据)读取默认目录
- Oracle 如何设置shared pool 和sga大细, 应该设置几大
- 脑电分析系列[MNE-Python-8]| 参考电极简介
- html得到画布的颜色的值,从画布上获取像素颜色
- 堆排序时间复杂度_堆排序算法
- 猫眼java开发工资_Java硕士京东工作1年,跳槽后他期望薪资26K,大家感觉他可以吗...
- Redis HyperLogLog
- STM8学习笔记---PWM变频输出
- springboot maven打包pom配置
- function core.php is missing,PHP代码
- Datatable转换为Json
- 泛函分析 06.03 线性算子的谱理论 - 有界自共轭线性算子的谱
- 易语言 实现程序被关闭时隐藏窗口
- 未受信任的企业级开发者_iPhone提示“未受信任的企业级开发者”怎么办?解决苹果手机APP不信任的方法...
- 如何制作gif动态图片
- matlab中的包文件夹管理:‘+’文件夹
- 负载均衡性能参数如何测评?
- excel两个字符串相减_Excel用Substitute函数替换的5个实例及与Replace函数的区别
- java课程设计atm机_java课程设计报告-自动取款机模拟程序.doc
- 在个人网站里搭建了自己的随机图片接口~
热门文章
- linux下设置定时器,linux定时器设置.
- rtc驱动模型及rx8025驱动学习
- 如何用计算机算tan2,arctan计算器(万能计算器在线使用)
- 消息队列(Message Queue)简介及其使用
- 东芝服务器报错误代码维修,东芝复印机错误代码和维修代码
- leapftp 3.0.1使用教程,leapftp 3.0.1使用教程图解
- 非常实用的“绿色电子地图”
- 计算广告学 学习资料
- 前端使用canvas拼接多张图片
- 移动侦测/周界入侵检测视频录像如何通过国标GB28181协议视频平台EasyGBS进行弹出告警