protected override void OnRecycle()
 {
     _dynamicAabbTree = null;
     _enumerator.Dispose();
     _enumerator = null;
     Pool.Recycle(this);
 }
示例#2
0
        private IEnumerable <Pair <T> > GetOverlapsImpl(Vector3F scale, DynamicAabbTree <T> otherTree, Vector3F otherScale, Pose otherPose)
        {
            // Compute transformations.
            Vector3F scaleA = scale; // Rename scales for readability.
            Vector3F scaleB = otherScale;
            Pose     bToA   = otherPose;

#if !POOL_ENUMERABLES
            var stack = DigitalRune.ResourcePools <Pair <Node, Node> > .Stacks.Obtain();

            stack.Push(new Pair <Node, Node>(_root, otherTree._root));
            while (stack.Count > 0)
            {
                var nodePair = stack.Pop();
                var nodeA    = nodePair.First;
                var nodeB    = nodePair.Second;

                if (HaveAabbContact(nodeA, scaleA, nodeB, scaleB, bToA))
                {
                    if (!nodeA.IsLeaf)
                    {
                        if (!nodeB.IsLeaf)
                        {
                            stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB.RightChild));
                            stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB.RightChild));
                            stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB.LeftChild));
                            stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB.LeftChild));
                        }
                        else
                        {
                            stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB));
                            stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB));
                        }
                    }
                    else
                    {
                        if (!nodeB.IsLeaf)
                        {
                            stack.Push(new Pair <Node, Node>(nodeA, nodeB.RightChild));
                            stack.Push(new Pair <Node, Node>(nodeA, nodeB.LeftChild));
                        }
                        else
                        {
                            // Leaf overlap.
                            var overlap = new Pair <T>(nodeA.Item, nodeB.Item);
                            if (Filter == null || Filter.Filter(overlap))
                            {
                                yield return(overlap);
                            }
                        }
                    }
                }
            }

            DigitalRune.ResourcePools <Pair <Node, Node> > .Stacks.Recycle(stack);
#else
            // Avoiding garbage:
            return(GetOverlapsWithTransformedTreeWork.Create(this, otherTree, ref scaleA, ref scaleB, ref bToA));
#endif
        }
示例#3
0
            public static IEnumerable <Pair <T> > Create(DynamicAabbTree <T> partition, DynamicAabbTree <T> otherPartition)
            {
                var enumerable = Pool.Obtain();

                enumerable._partition = partition;
                enumerable._stack.Push(new Pair <Node, Node>(partition._root, otherPartition._root));
                return(enumerable);
            }
示例#4
0
            public static IEnumerable <Pair <T> > Create(DynamicAabbTree <T> partition, ISpatialPartition <T> otherPartition)
            {
                var enumerable = Pool.Obtain();

                enumerable._partition      = partition;
                enumerable._otherPartition = otherPartition;
                enumerable._leafNodes      = partition.GetLeafNodes(otherPartition.Aabb).GetEnumerator();
                return(enumerable);
            }
            public static IEnumerable <T> Create(DynamicAabbTree <T> aabbTree, Node leaf)
            {
                var enumerable = Pool.Obtain();

                enumerable._leaf = leaf;
                if (aabbTree._root != null)
                {
                    enumerable._stack.Push(aabbTree._root);
                }
                return(enumerable);
            }
            public static IEnumerable <T> Create(DynamicAabbTree <T> aabbTree, ref Aabb aabb)
            {
                var enumerable = Pool.Obtain();

                enumerable._aabb = aabb;
                if (aabbTree._root != null)
                {
                    enumerable._stack.Push(aabbTree._root);
                }
                return(enumerable);
            }
            public static IEnumerable <T> Create(DynamicAabbTree <T> dynamicAabbTree, T item)
            {
                var enumerable = Pool.Obtain();

                enumerable._dynamicAabbTree = dynamicAabbTree;
                enumerable._item            = item;
                Aabb aabb = dynamicAabbTree.GetAabbForItem(item);

                enumerable._enumerator = dynamicAabbTree.GetOverlaps(aabb).GetEnumerator();
                return(enumerable);
            }
示例#8
0
            public static IEnumerable <Pair <T> > Create(DynamicAabbTree <T> partition, DynamicAabbTree <T> otherPartition,
                                                         ref Vector3F scaleA, ref Vector3F scaleB, ref Pose bToA)
            {
                var enumerable = Pool.Obtain();

                enumerable._partition = partition;
                enumerable._stack.Push(new Pair <Node, Node>(partition._root, otherPartition._root));
                enumerable._scaleA = scaleA;
                enumerable._scaleB = scaleB;
                enumerable._bToA   = bToA;
                return(enumerable);
            }
示例#9
0
 protected override void OnRecycle()
 {
     _partition      = null;
     _otherPartition = null;
     _leafNodes.Dispose();
     _leafNodes = null;
     if (_otherCandidates != null)
     {
         _otherCandidates.Dispose();
         _otherCandidates = null;
     }
     Pool.Recycle(this);
 }
示例#10
0
            public static IEnumerable <Pair <T> > Create(DynamicAabbTree <T> partition,
                                                         ISpatialPartition <T> otherPartition, IEnumerable <Node> leafNodes,
                                                         ref Vector3F scale, ref Vector3F otherScaleInverse, ref Pose toOther)
            {
                var enumerable = Pool.Obtain();

                enumerable._partition         = partition;
                enumerable._otherPartition    = otherPartition;
                enumerable._leafNodes         = leafNodes.GetEnumerator();
                enumerable._scale             = scale;
                enumerable._otherScaleInverse = otherScaleInverse;
                enumerable._toOther           = toOther;
                return(enumerable);
            }
            public static IEnumerable <T> Create(DynamicAabbTree <T> aabbTree, ref Ray ray)
            {
                var enumerable = Pool.Obtain();

                enumerable._ray = ray;
                enumerable._rayDirectionInverse = new Vector3F(1 / ray.Direction.X,
                                                               1 / ray.Direction.Y,
                                                               1 / ray.Direction.Z);
                enumerable._epsilon = Numeric.EpsilonF * (1 + aabbTree.Aabb.Extent.Length);
                if (aabbTree._root != null)
                {
                    enumerable._stack.Push(aabbTree._root);
                }
                return(enumerable);
            }
            public static IEnumerable <T> Create(DynamicAabbTree <T> aabbTree, IList <Plane> planes)
            {
                var enumerable = Pool.Obtain();

                enumerable._planes = planes;
                int numberOfPlanes = planes.Count;

                if (enumerable._signs.Length < numberOfPlanes)
                {
                    enumerable._signs = new int[numberOfPlanes];
                }
                for (int i = 0; i < numberOfPlanes; i++)
                {
                    enumerable._signs[i] = ((planes[i].Normal.X >= 0) ? 1 : 0)
                                           + ((planes[i].Normal.Y >= 0) ? 2 : 0)
                                           + ((planes[i].Normal.Z >= 0) ? 4 : 0);
                }
                enumerable._inside = (1 << numberOfPlanes) - 1;
                if (aabbTree._root != null)
                {
                    enumerable._stack0.Push(new Pair <Node, int>(aabbTree._root, 0));
                }
                return(enumerable);
            }
示例#13
0
 protected override void OnRecycle()
 {
     _partition = null;
     _stack.Clear();
     Pool.Recycle(this);
 }
示例#14
0
        private IEnumerable <Pair <T> > GetOverlapsImpl(DynamicAabbTree <T> otherTree)
        {
#if !POOL_ENUMERABLES
            var stack = DigitalRune.ResourcePools <Pair <Node, Node> > .Stacks.Obtain();

            stack.Push(new Pair <Node, Node>(_root, otherTree._root));
            while (stack.Count > 0)
            {
                var nodePair = stack.Pop();
                var nodeA    = nodePair.First;
                var nodeB    = nodePair.Second;

                if (nodeA == nodeB)
                {
                    if (!nodeA.IsLeaf)
                    {
                        stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeA.RightChild));
                        stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeA.RightChild));
                        stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeA.LeftChild));
                    }
                }
                else if (GeometryHelper.HaveContact(nodeA.Aabb, nodeB.Aabb))
                {
                    if (!nodeA.IsLeaf)
                    {
                        if (!nodeB.IsLeaf)
                        {
                            stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB.RightChild));
                            stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB.RightChild));
                            stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB.LeftChild));
                            stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB.LeftChild));
                        }
                        else
                        {
                            stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB));
                            stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB));
                        }
                    }
                    else
                    {
                        if (!nodeB.IsLeaf)
                        {
                            stack.Push(new Pair <Node, Node>(nodeA, nodeB.RightChild));
                            stack.Push(new Pair <Node, Node>(nodeA, nodeB.LeftChild));
                        }
                        else
                        {
                            // Leaf overlap.
                            var overlap = new Pair <T>(nodeA.Item, nodeB.Item);
                            if (Filter == null || Filter.Filter(overlap))
                            {
                                yield return(overlap);
                            }
                        }
                    }
                }
            }

            DigitalRune.ResourcePools <Pair <Node, Node> > .Stacks.Recycle(stack);
#else
            // Avoiding garbage:
            return(GetOverlapsWithTreeWork.Create(this, otherTree));
#endif
        }