Exemple #1
0
        private bool OverlapWithOffset(Tuple <ITreeItem, ITreeItem> pair)
        {
            var stack = new Stack <Tuple <ITreeItem, ITreeItem> >();

            stack.Push(pair);
            while (stack.Count > 0)
            {
                pair = stack.Pop();
                var itemA = pair.Item1;
                var itemB = pair.Item2;
                if (!itemA.CanSubdivide && !itemB.CanSubdivide)
                {
                    var triA = treeA.GetItem(itemA.ID);
                    var triB = treeB.GetItem(itemB.ID);

                    if (!outerIntersectFound)
                    {
                        var offSetTriA = meshA.CreateOuterTriangle(triA, currentPositivOffset);
                        var offSetTriB = meshB.CreateOuterTriangle(triB, currentPositivOffset);
                        outerIntersectFound = triangleIntersector.DoIntersect(offSetTriA, offSetTriB);
                    }

                    var offSetTriA2         = meshA.CreateOuterTriangle(triA, currentNegativeOffset);
                    var offSetTriB2         = meshB.CreateOuterTriangle(triB, currentNegativeOffset);
                    var innerIntersectFound = triangleIntersector.DoIntersect(offSetTriA2, offSetTriB2);
                    if (innerIntersectFound)
                    {
                        return(false);
                    }
                }
                else
                {
                    var mainItemChildren = MeOrMyChildren(itemA);
                    foreach (var childA in mainItemChildren)
                    {
                        var itemBChildren = MeOrMyChildren(itemB);
                        foreach (var childB in itemBChildren)
                        {
                            var childAOffsetBox = childA.Bounds.Offset(settings.Touch.PositiveOffset);
                            var childBOffsetBox = childB.Bounds.Offset(settings.Touch.PositiveOffset);
                            intersectingCall++;

                            if (childAOffsetBox.Intersects(childBOffsetBox))
                            {
                                stack.Push(new Tuple <ITreeItem, ITreeItem>(childA, childB));
                            }
                        }
                    }
                }
            }
            return(outerIntersectFound);
        }
Exemple #2
0
        private double Distance(IEnumerable <Tuple <ITreeItem, ITreeItem> > outList)
        {
            var minDist = double.MaxValue;

            foreach (var tuple in outList)
            {
                var nodeA = tuple.Item1;
                var nodeB = tuple.Item2;

                var triesA = treeA.GetItem(nodeA.ID);
                var triesB = treeB.GetItem(nodeB.ID);

                var dist = triesA.MinSqrDistance(triesB);
                if (dist < minDist)
                {
                    minDist = dist;
                }

                if (minDist < settings.Distance.RoundToZero)
                {
                    return(0);
                }
            }

            return(minDist);
        }
Exemple #3
0
        private bool OverlapWithMinusOffset(List <List <ITreeItem> > treeItemListList)
        {
            var listListOut = new List <List <ITreeItem> >();

            if (treeItemListList.Count == 0)
            {
                return(false);
            }

            foreach (var treeItems in treeItemListList)
            {
                var mainItem         = treeItems[0];
                var mainCanSubdivide = mainItem.CanSubdivide;

                var mainItemChildren = MeOrMyChildren(mainItem);

                for (int i = 1; i < treeItems.Count; i++)
                {
                    var testeeCanSubdivide = treeItems[i].CanSubdivide;

                    if (!mainCanSubdivide && !testeeCanSubdivide)
                    {
                        var triA = treeA.GetItem(mainItem.ID);
                        var triB = treeB.GetItem(treeItems[i].ID);

                        var offSetTriA = meshA.CreateOuterTriangle(triA, currentMinusOffset);
                        var offSetTriB = meshB.CreateOuterTriangle(triB, currentMinusOffset);
                        if (triangleIntersector.DoIntersect(offSetTriA, offSetTriB))
                        {
                            exporter.ExportMeshes(@"_TriOri.x3d", new List <TriangleMesh>()
                            {
                                new TriangleMesh(new List <Triangle>()
                                {
                                    triA, triB
                                }, "original", false)
                            });

                            exporter.ExportMeshes(@"_TriInner.x3d", new List <TriangleMesh>()
                            {
                                new TriangleMesh(new List <Triangle>()
                                {
                                    offSetTriA, offSetTriB
                                }, "iinner", false)
                            });

                            return(true);
                        }


                        continue;
                    }

                    var testeeChildren = MeOrMyChildren(treeItems[i]);

                    foreach (var mainChild in mainItemChildren)
                    {
                        var listOut = new List <ITreeItem>();
                        listOut.Add(mainChild);

                        foreach (var testeeChild in testeeChildren)
                        {
                            var isIntersecting = mainChild.Bounds.Intersects(testeeChild.Bounds);
                            if (isIntersecting)
                            {
                                listOut.Add(testeeChild);
                            }
                        }

                        if (listOut.Count > 1)
                        {
                            listListOut.Add(listOut);
                        }
                    }
                }
            }

            return(OverlapWithMinusOffset(listListOut));
        }