Exemplo n.º 1
0
        public IList <KeyValuePair <uint, bool> > GetEdgesForConnectVertex(VertexEdgeItr vItr1, VertexEdgeItr vItr2)
        {
            IList <KeyValuePair <uint, bool> > eId2Dir = new List <KeyValuePair <uint, bool> >();;

            uint uVId1 = vItr1.GetUseVertexId();
            uint uVId2 = vItr2.GetUseVertexId();

            if (!BRep.IsUseVertexId(uVId1))
            {
                return(eId2Dir);
            }
            if (!BRep.IsUseVertexId(uVId2))
            {
                return(eId2Dir);
            }
            if (uVId1 == uVId2)
            {
                return(eId2Dir);
            }
            if (vItr1.GetLoopId() != vItr2.GetLoopId())
            {
                return(eId2Dir);
            }

            uint hEId1 = vItr1.GetHalfEdgeId();
            uint uLId1;
            {
                System.Diagnostics.Debug.Assert(BRep.IsHalfEdgeId(hEId1));
                HalfEdge hE1 = BRep.GetHalfEdge(hEId1);
                uLId1 = hE1.ULId;
                System.Diagnostics.Debug.Assert(hE1.EId != 0);
            }
            uint hEId2 = vItr2.GetHalfEdgeId();
            uint uLId2;

            {
                System.Diagnostics.Debug.Assert(BRep.IsHalfEdgeId(hEId2));
                HalfEdge hE2 = BRep.GetHalfEdge(hEId2);
                uLId2 = hE2.ULId;
                System.Diagnostics.Debug.Assert(hE2.EId != 0);
            }

            if (uLId1 != uLId2)
            {
                return(eId2Dir);
            }
            uint hEId = hEId2;

            while (true)
            {
                HalfEdge hE = BRep.GetHalfEdge(hEId);
                eId2Dir.Add(new KeyValuePair <uint, bool>(hE.EId, hE.IsSameDir));
                hEId = hE.FHEId;
                if (hEId == hEId1)
                {
                    break;
                }
            }
            return(eId2Dir);
        }
Exemplo n.º 2
0
        public ConnectVertexRes ConnectVertex(VertexEdgeItr vItr1, VertexEdgeItr vItr2, bool isLeftAddL)
        {
            ConnectVertexRes res = new ConnectVertexRes();

            uint uVId1 = vItr1.GetUseVertexId();
            uint uVId2 = vItr2.GetUseVertexId();

            if (!BRep.IsUseVertexId(uVId1))
            {
                return(res);
            }
            if (!BRep.IsUseVertexId(uVId2))
            {
                return(res);
            }
            if (uVId1 == uVId2)
            {
                return(res);
            }
            res.VId1 = BRep.GetUseVertex(uVId1).VId;
            res.VId2 = BRep.GetUseVertex(uVId2).VId;

            if (vItr1.GetLoopId() != vItr2.GetLoopId())
            {
                return(res);
            }
            uint lId = vItr1.GetLoopId();

            res.LId = lId;

            uint hEId1 = vItr1.GetHalfEdgeId();
            uint hEId2 = vItr2.GetHalfEdgeId();

            uint uLId1;
            bool isFloat1;
            {
                System.Diagnostics.Debug.Assert(BRep.IsHalfEdgeId(hEId1));
                HalfEdge hE1 = BRep.GetHalfEdge(hEId1);
                uLId1 = hE1.ULId;
                System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(uLId1));
                isFloat1 = (hE1.EId == 0);
            }
            uint uLId2;
            bool isFloat2;

            {
                System.Diagnostics.Debug.Assert(BRep.IsHalfEdgeId(hEId2));
                HalfEdge hE2 = BRep.GetHalfEdge(hEId2);
                uLId2 = hE2.ULId;
                System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(uLId2));
                isFloat2 = (hE2.EId == 0);
            }

            if (uLId1 != uLId2)
            {
                if (isFloat1 && !isFloat2)
                {
                    uint addHEId1;
                    if (!BRep.MEKLOneFloatingVertex(out addHEId1, hEId2, hEId1))
                    {
                        System.Diagnostics.Debug.Assert(false);
                    }
                    uint addEId = GetFreeKey(Edge2HalfEdge);
                    BRep.SetHalfEdgeEdgeId(addHEId1, addEId, false);
                    BRep.SetHalfEdgeEdgeId(hEId1, addEId, true);
                    Edge2HalfEdge.Add(addEId, hEId1);
                    System.Diagnostics.Debug.Assert(AssertValid());
                    res.AddEId = addEId;
                    return(res);
                }
                else if (isFloat2 && !isFloat1)
                {
                    uint addHEId1;
                    if (!BRep.MEKLOneFloatingVertex(out addHEId1, hEId1, hEId2))
                    {
                        System.Diagnostics.Debug.Assert(false);
                    }
                    uint addEId = GetFreeKey(Edge2HalfEdge);
                    BRep.SetHalfEdgeEdgeId(addHEId1, addEId, true);
                    BRep.SetHalfEdgeEdgeId(hEId2, addEId, false);
                    Edge2HalfEdge.Add(addEId, addHEId1);
                    System.Diagnostics.Debug.Assert(AssertValid());
                    res.AddEId = addEId;
                    return(res);
                }
                else if (isFloat1 && isFloat2)
                {
                    if (!BRep.MEKLTwoFloatingVertex(hEId1, hEId2))
                    {
                        System.Diagnostics.Debug.Assert(false);
                    }
                    uint addEId = GetFreeKey(Edge2HalfEdge);
                    BRep.SetHalfEdgeEdgeId(hEId1, addEId, true);
                    BRep.SetHalfEdgeEdgeId(hEId2, addEId, false);
                    Edge2HalfEdge.Add(addEId, hEId1);
                    System.Diagnostics.Debug.Assert(AssertValid());
                    res.AddEId = addEId;
                    return(res);
                }
                else
                {
                    uint addHEId1;
                    uint addHEId2;
                    if (!BRep.MEKL(out addHEId1, out addHEId2, hEId1, hEId2))
                    {
                        System.Diagnostics.Debug.Assert(false);
                    }
                    uint addEId = GetFreeKey(Edge2HalfEdge);
                    BRep.SetHalfEdgeEdgeId(addHEId1, addEId, true);
                    BRep.SetHalfEdgeEdgeId(addHEId2, addEId, false);
                    Edge2HalfEdge.Add(addEId, addHEId1);
                    if (lId != 0)
                    {
                        uint parentULId1 = BRep.GetUseLoop(uLId1).ParentULId;
                        System.Diagnostics.Debug.Assert(parentULId1 != 0);
                        System.Diagnostics.Debug.Assert(Loop2UseLoop.ContainsKey(lId));
                        Loop2UseLoop[lId] = parentULId1;
                    }
                    else
                    {
                    }
                    System.Diagnostics.Debug.Assert(AssertValid());
                    res.AddEId = addEId;
                    return(res);
                }
            }
            else if (uLId1 == uLId2)
            {
                uint addHEId1;
                uint addHEId2;
                uint addULId;
                if (!BRep.MEL(out addHEId1, out addHEId2, out addULId, hEId1, hEId2))
                {
                    System.Diagnostics.Debug.Assert(false);
                }
                System.Diagnostics.Debug.Assert(BRep.AssertValidUse() == 0);
                uint addEId = GetFreeKey(Edge2HalfEdge);
                BRep.SetHalfEdgeEdgeId(addHEId1, addEId, true);
                BRep.SetHalfEdgeEdgeId(addHEId2, addEId, false);

                Edge2HalfEdge.Add(addEId, addHEId1);
                bool iflag = true;
                if (lId == 0)
                {
                    iflag = !isLeftAddL;
                }
                else
                {
                    uint parentULId = Loop2UseLoop[lId];
                    if (uLId1 != parentULId)
                    {
                        if (isLeftAddL)
                        {
                            BRep.SwapUseLoop(addULId, uLId1);
                            BRep.SetUseLoopLoopId(addULId, lId);
                            BRep.AssertValidUse();
                            iflag = false;
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                    }
                }

                uint addLId = GetFreeKey(Loop2UseLoop);
                if (iflag)
                {
                    Loop2UseLoop.Add(addLId, addULId);
                    BRep.SetUseLoopLoopId(addULId, addLId);
                }
                else
                {
                    Loop2UseLoop.Add(addLId, uLId1);
                    BRep.SetUseLoopLoopId(uLId1, addLId);
                }
                System.Diagnostics.Debug.Assert(AssertValid());
                res.AddEId     = addEId;
                res.AddLId     = addLId;
                res.IsLeftAddL = !iflag;
                return(res);
            }
            System.Diagnostics.Debug.Assert(false);
            return(res);
        }