Beispiel #1
0
        private void AddData(OctTreeNode node, T dataType)
        {
            if (node.Data == null)
            {
                node.Data = new Dictionary <Tkey, T>();
            }

            node.Data.Add(dataType.Key, dataType);

            var children = node.Children;

            if (children != null)
            {
                //Debug.Assert(children.Count == 8);

                foreach (var child in children)
                {
                    if (child.Contains(dataType))
                    {
                        AddData(child, dataType);
                        //we have found which child it is in ..we don't need to continue any further on this rescurse.
                        break;
                    }
                }
            }
        }
        public ProximityMap(SearchFunctionDelegate <T> searchFunc,
                            AddObjectsFunctionDelegate <T> findFunc,
                            float fWorldSize,
                            int nMaxDepth,
                            Vector3 v3Center,
                            object searchableData,
                            GraphicsDevice device)
        {
            m_searchFunc = searchFunc;
            m_findFunc   = findFunc;

            OctTreeNode <T> .InitialiseGraphics(device);

            m_octreeRoot = new OctTreeNode <T>(nMaxDepth, 0, fWorldSize, v3Center, findFunc, searchableData);
        }
Beispiel #3
0
        private void QueryNodesAgainstDataRay(OctTreeNode startNode, Ray ray, int numberOfLayers, List <List <T> > nodes)
        {
            nodes.Add(startNode.Data.Values.ToList());

            var children = startNode.Children;

            if (children != null)
            {
                Debug.Assert(children.Count == 8);

                foreach (var child in children)
                {
                    if (child.IntersectsRay(ray))
                    {
                        QueryNodesAgainstDataRay(child, ray, numberOfLayers, nodes);
                        break;
                    }
                }
            }
        }
        private void DrawCub(OctTreeNode <AABB> tree)
        {
            //Gizmos.color = new Color(0.9f, 0.6f, 0.1f);
            if (null == tree)
            {
                return;
            }
            //if (0 == tree.depth&&null == tree.data)
            //    Gizmos.DrawWireCube(tree.center, tree.radius);
            if (null != tree.data)
            {
                Gizmos.color = new Color(1f, 1f, 1f);
                Gizmos.DrawCube(tree.center, tree.radius);
            }

            for (int i = 0; i < tree.child.Length; ++i)
            {
                DrawCub(tree.child[i]);
            }
        }
Beispiel #5
0
        private void GenerateChildren(OctTreeNode node, int layer)
        {
            node.Children = new List <OctTreeNode>(8);

            Vector3 center = node.Center;
            Vector3 min    = node.Min;
            Vector3 max    = node.Max;
            Vector3 size   = node.Size;

            List <OctTreeNodeData> nodeData = new List <OctTreeNodeData>();

            //bottom left back.
            Vector3 halfSize = size / 2;

            nodeData.Add(new OctTreeNodeData
            {
                Position = (center + min) / 2,
                Size     = halfSize//(center - min)
            });

            //top left back
            Vector3 minBottom = new Vector3(min.x, min.y + size.y, min.z);

            nodeData.Add(new OctTreeNodeData
            {
                Position = (center + minBottom) / 2,
                Size     = halfSize//(center - minBottom)
            });

            //front left bottom
            Vector3 minFront = new Vector3(min.x + size.x, min.y, min.z);

            nodeData.Add(new OctTreeNodeData
            {
                Position = (center + minFront) / 2,
                Size     = halfSize//(center - minFront)
            });

            //front left top
            Vector3 minBottomFront = new Vector3(min.x + size.x, min.y + size.y, min.z);

            nodeData.Add(new OctTreeNodeData
            {
                Position = (center + minBottomFront) / 2,
                Size     = halfSize//(center - minBottomFront)
            });

            //----------------------------------------------

            //front right top.
            nodeData.Add(new OctTreeNodeData
            {
                Position = (center + max) / 2,
                Size     = halfSize//(max - center)
            });


            //front right bottom.
            Vector3 maxFrontTop = new Vector3(max.x, max.y - size.y, max.z);

            nodeData.Add(new OctTreeNodeData
            {
                Position = (center + maxFrontTop) / 2,
                Size     = halfSize//(maxFrontTop - center)
            });

            //back right bottom.
            Vector3 backRightBottom = new Vector3(max.x - size.x, max.y, max.z);

            nodeData.Add(new OctTreeNodeData
            {
                Position = (center + backRightBottom) / 2,
                Size     = halfSize//(backRightBottom - center)
            });

            Vector3 backRightTop = new Vector3(max.x - size.x, max.y - size.y, max.z);

            nodeData.Add(new OctTreeNodeData
            {
                Position = (center + backRightTop) / 2,
                Size     = halfSize//(backRightTop - center)
            });

            foreach (var data in nodeData)
            {
                node.Children.Add(new OctTreeNode(data.Position, data.Size));
            }

            ++layer;

            if (layer <= m_currentNumberOfLayers)
            {
                foreach (var child in node.Children)
                {
                    GenerateChildren(child, layer);
                }
            }
        }
Beispiel #6
0
        //Vector3 m_facing;

        public OctTree(OctTreeNode root)
        {
            m_root = root;
            //m_facing = facing.normalized;
        }
Beispiel #7
0
			public FastOctTreeNode (OctTreeNode node) {
				if(node is OctTreeInnerNode) {
					OctTreeInnerNode otin = (OctTreeInnerNode)node;
					this.x = otin.x;
					this.y = otin.y;
					this.z = otin.z;
					this.node = new FastOctTreeNode[0x08];
					for(int i = 0; i < 0x08; i++) {
						this.node[i] = new FastOctTreeNode(otin.children[i]);
					}
				}
				else {
					this.node = null;
					this.data = ((OctTreeLeaf)node).sl.ToLongRepresentation();
				}
			}
Beispiel #8
0
			public OctTreeInnerNode (double x, double y, double z, OctTreeNode[] children) {
				this.x = x;
				this.y = y;
				this.z = z;
				this.children = children;
			}
Beispiel #9
0
		private OctTreeNode Order (SplitDimensionHeuristic sdh, List<MarkedItem>[] caches, int depth, double x0, double x1, double y0, double y1, double z0, double z1) {
			List<MarkedItem> currentCache = caches[depth];
			if(currentCache.Count > maxNodeItems && (depth < maxDepth || depth <= 0x00)) {
				List<MarkedItem> nextCache = caches[depth+0x01];
				double dummy;
				double x2 = sdh(currentCache.Select(r => r.Item2), 0x00, x0, x1, out dummy);
				double y2 = sdh(currentCache.Select(r => r.Item2), 0x01, y0, y1, out dummy);
				double z2 = sdh(currentCache.Select(r => r.Item2), 0x02, z0, z1, out dummy);
				OctTreeNode[] children = new OctTreeNode[0x08];
				nextCache.AddRange(currentCache.Where(x => x.Item2.BoxOverlap(x0, x2, y0, y2, z0, z2) && x.Item2.InBox(x0, x2, y0, y2, z0, z2)));
				children[0x00] = Order(sdh, caches, depth+0x01, x0, x2, y0, y2, z0, z2);
				nextCache.Clear();
				nextCache.AddRange(currentCache.Where(x => x.Item2.BoxOverlap(x0, x2, y0, y2, z2, z1) && x.Item2.InBox(x0, x2, y0, y2, z2, z1)));
				children[0x01] = Order(sdh, caches, depth+0x01, x0, x2, y0, y2, z2, z1);
				nextCache.Clear();
				nextCache.AddRange(currentCache.Where(x => x.Item2.BoxOverlap(x0, x2, y2, y1, z0, z2) && x.Item2.InBox(x0, x2, y2, y1, z0, z2)));
				children[0x02] = Order(sdh, caches, depth+0x01, x0, x2, y2, y1, z0, z2);
				nextCache.Clear();
				nextCache.AddRange(currentCache.Where(x => x.Item2.BoxOverlap(x0, x2, y2, y1, z2, z1) && x.Item2.InBox(x0, x2, y2, y1, z2, z1)));
				children[0x03] = Order(sdh, caches, depth+0x01, x0, x2, y2, y1, z2, z1);
				nextCache.Clear();
				nextCache.AddRange(currentCache.Where(x => x.Item2.BoxOverlap(x2, x1, y0, y2, z0, z2) && x.Item2.InBox(x2, x1, y0, y2, z0, z2)));
				children[0x04] = Order(sdh, caches, depth+0x01, x2, x1, y0, y2, z0, z2);
				nextCache.Clear();
				nextCache.AddRange(currentCache.Where(x => x.Item2.BoxOverlap(x2, x1, y0, y2, z2, z1) && x.Item2.InBox(x2, x1, y0, y2, z2, z1)));
				children[0x05] = Order(sdh, caches, depth+0x01, x2, x1, y0, y2, z2, z1);
				nextCache.Clear();
				nextCache.AddRange(currentCache.Where(x => x.Item2.BoxOverlap(x2, x1, y2, y1, z0, z2) && x.Item2.InBox(x2, x1, y2, y1, z0, z2)));
				children[0x06] = Order(sdh, caches, depth+0x01, x2, x1, y2, y1, z0, z2);
				nextCache.Clear();
				nextCache.AddRange(currentCache.Where(x => x.Item2.BoxOverlap(x2, x1, y2, y1, z2, z1) && x.Item2.InBox(x2, x1, y2, y1, z2, z1)));
				children[0x07] = Order(sdh, caches, depth+0x01, x2, x1, y2, y1, z2, z1);
				nextCache.Clear();
				return new OctTreeInnerNode(x2, y2, z2, children);

			}
			else {
				return new OctTreeLeaf(currentCache.Select(x => x.Item1));
			}
		}