Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private bool EmitRays(Triangle triangle2, List <Triangle> candidateTriangles1, TriangleMesh mesh1, Axis axis, bool positiveDirection)
        {
            var positiveOffset = settings.Direction.PositiveOffset;

            foreach (var samplePoint in triangle2.SamplingPoints)
            {
                var direction = positiveDirection ? AxisDirection.Positive : AxisDirection.Negative;
                var ray       = new Ray(samplePoint, axis, direction);

                var doesIntersect = false;
                foreach (var candidateTriangle in candidateTriangles1)
                {
                    var outerTri = mesh1.CreateOuterTriangle(candidateTriangle, positiveOffset);
                    doesIntersect = rayTriangleIntersector.TestStrict(ray, outerTri);
                    if (doesIntersect)
                    {
                        break;
                    }
                }

                if (!doesIntersect)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        public TriangleMesh OuterMesh(TriangleMesh mesh, double minusOffset)
        {
            var tris = new List <Triangle>();

            foreach (var triangle in mesh.Triangles)
            {
                var offSetTriA = mesh.CreateOuterTriangle(triangle, minusOffset);
                tris.Add(offSetTriA);
            }

            return(new TriangleMesh(tris, "test", false));
        }
Ejemplo n.º 4
0
        private bool DirectionRelaxed(TriangleMesh meshA, TriangleMesh meshB, Axis axis, bool positiveDirection)
        {
            var boxesEx = new List <Box>();

            var box1 = meshA.Bounds;
            var box2 = meshB.Bounds;

            var isAboveRelaxed = box1.IntersectsColumm(box2, axis, positiveDirection);

            if (!isAboveRelaxed)
            {
                return(false);
            }



            var transLength = Box.Union(box1, box2).GetInterval(axis).Length;

            foreach (var triangle1 in meshA.Triangles)
            {
                var triangle1Inner = meshA.CreateOuterTriangle(triangle1, settings.Direction.PositiveOffset);

                var tree1BoxExtended = triangle1Inner.Bounds.ExtendInDirection(box2, axis, positiveDirection);

                boxesEx.Add(tree1BoxExtended);

                var tree2TrianglesCandidates = meshB.RTreeRoot.FindOverlap(tree1BoxExtended).ToList();

                if (tree2TrianglesCandidates.Count == 0)
                {
                    continue;
                }

                var prism = new Prism(triangle1Inner, transLength, axis, positiveDirection);
                foreach (var triangle2 in tree2TrianglesCandidates)
                {
                    if (prismTriangleIntersection.Test(prism, triangle2))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        private bool IsInside(TriangleMesh meshA, TriangleMesh meshB)
        {
            var boxA = meshA.Bounds;

            var aBTri = meshB.Triangles[0];

            aBTri = meshB.CreateOuterTriangle(aBTri, negativeOffset);

            var center      = aBTri.Center.Vector;
            var rayPositive = new Ray(center, Axis.X, AxisDirection.Positive);
            var rayNegative = new Ray(center, Axis.X, AxisDirection.Negative);
            var aBTriBoxExtendedPositive = aBTri.Bounds.ExtendInDirection(boxA, Axis.X, true);
            var aBTriBoxExtendedNegative = aBTri.Bounds.ExtendInDirection(boxA, Axis.X, false);

            var isInsideP = IntersectionCount(meshA, aBTriBoxExtendedPositive, rayPositive);
            var isInsideN = IntersectionCount(meshA, aBTriBoxExtendedNegative, rayNegative);

            if (isInsideP != isInsideN)
            {
                throw new InvalidOperationException();
            }

            return(isInsideP);
        }
Ejemplo n.º 6
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));
        }