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);
            }
            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);
            }
            public static IEnumerable <Pair <T> > Create(AdaptiveAabbTree <T> partition, AdaptiveAabbTree <T> otherPartition,
                                                         ref Vector3 scaleA, ref Vector3 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);
            }
 protected override void OnRecycle()
 {
     _partition      = null;
     _otherPartition = null;
     _leafNodes.Dispose();
     _leafNodes = null;
     if (_otherCandidates != null)
     {
         _otherCandidates.Dispose();
         _otherCandidates = null;
     }
     Pool.Recycle(this);
 }
            public static IEnumerable <Pair <T> > Create(AdaptiveAabbTree <T> partition,
                                                         ISpatialPartition <T> otherPartition, IEnumerable <Node> leafNodes,
                                                         ref Vector3 scale, ref Vector3 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 Vector3(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);
            }
 protected override void OnRecycle()
 {
     _partition = null;
     _stack.Clear();
     Pool.Recycle(this);
 }
Exemple #9
0
    private IEnumerable<Pair<T>> GetOverlapsImpl(AdaptiveAabbTree<T> otherTree)
    {

      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);

    }
Exemple #10
0
    private IEnumerable<Pair<T>> GetOverlapsImpl(Vector3 scale, AdaptiveAabbTree<T> otherTree, Vector3 otherScale, Pose otherPose)
    {
      // Compute transformations.
      Vector3 scaleA = scale;      // Rename scales for readability.
      Vector3 scaleB = otherScale;
      Pose bToA = otherPose;


      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);

    }