Exemple #1
0
            public static IEnumerable <Pair <T> > Create(AdaptiveAabbTree <T> partition, AdaptiveAabbTree <T> otherPartition)
            {
                var enumerable = Pool.Obtain();

                enumerable._partition = partition;
                enumerable._stack.Push(new Pair <Node, Node>(partition._root, otherPartition._root));
                return(enumerable);
            }
Exemple #2
0
            public static IEnumerable <Pair <T> > Create(AdaptiveAabbTree <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 <Node> Create(AdaptiveAabbTree <T> aabbTree, ref Aabb aabb)
            {
                var enumerable = Pool.Obtain();

                enumerable._aabb = aabb;
                if (aabbTree._root != null)
                {
                    enumerable._stack.Push(aabbTree._root);
                }
                return(enumerable);
            }
Exemple #4
0
            public static IEnumerable <Pair <T> > Create(AdaptiveAabbTree <T> partition, AdaptiveAabbTree <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);
            }
Exemple #5
0
 protected override void OnRecycle()
 {
     _partition      = null;
     _otherPartition = null;
     _leafNodes.Dispose();
     _leafNodes = null;
     if (_otherCandidates != null)
     {
         _otherCandidates.Dispose();
         _otherCandidates = null;
     }
     Pool.Recycle(this);
 }
Exemple #6
0
            public static IEnumerable <Pair <T> > Create(AdaptiveAabbTree <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(AdaptiveAabbTree <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);
            }
Exemple #8
0
 protected override void OnRecycle()
 {
     _partition = null;
     _stack.Clear();
     Pool.Recycle(this);
 }
        private IEnumerable <Pair <T> > GetOverlapsImpl(AdaptiveAabbTree <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;

                nodeA.IsActive = true;
                nodeB.IsActive = true;

                if (nodeA == nodeB)
                {
                    if (!nodeA.IsLeaf)
                    {
                        SplitIfNecessary(nodeA);
                        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)
                        {
                            SplitIfNecessary(nodeA);
                            SplitIfNecessary(nodeB);
                            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
                        {
                            SplitIfNecessary(nodeA);
                            stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB));
                            stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB));
                        }
                    }
                    else
                    {
                        if (!nodeB.IsLeaf)
                        {
                            SplitIfNecessary(nodeB);
                            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
        }
        private IEnumerable <Pair <T> > GetOverlapsImpl(Vector3F scale, AdaptiveAabbTree <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;

                nodeA.IsActive = true;
                nodeB.IsActive = true;

                if (HaveAabbContact(nodeA, scaleA, nodeB, scaleB, bToA))
                {
                    if (!nodeA.IsLeaf)
                    {
                        if (!nodeB.IsLeaf)
                        {
                            SplitIfNecessary(nodeA);
                            SplitIfNecessary(nodeB);
                            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
                        {
                            SplitIfNecessary(nodeA);
                            stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB));
                            stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB));
                        }
                    }
                    else
                    {
                        if (!nodeB.IsLeaf)
                        {
                            SplitIfNecessary(nodeB);
                            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
        }