Exemplo n.º 1
0
        public bool RemoveVertex(uint vId)
        {
            uint uVId = vId;

            if (!BRep.IsUseVertexId(uVId))
            {
                return(false);
            }

            uint nEdgeAroundVtx = 0;

            {
                VertexEdgeItr vItr = new VertexEdgeItr(this, vId);
                nEdgeAroundVtx = vItr.GetEdgeCount();
            }

            if (nEdgeAroundVtx == 0)
            {
                System.Diagnostics.Debug.Assert(BRep.IsUseVertexId(uVId));
                if (!BRep.KVEL(uVId))
                {
                    System.Diagnostics.Debug.Assert(false);
                }
            }
            else if (nEdgeAroundVtx == 2)
            {
                UseVertex uV    = BRep.GetUseVertex(uVId);
                uint      hEId1 = uV.HEId;
                HalfEdge  hE1   = BRep.GetHalfEdge(hEId1);
                uint      eId1  = hE1.EId;
                uint      hEId2 = hE1.OHEId;
                HalfEdge  hE2   = BRep.GetHalfEdge(hEId2);
                {
                    uint        uLId1 = hE1.ULId;
                    uint        uLId2 = hE2.ULId;
                    LoopEdgeItr lItr1 = new LoopEdgeItr(this, hEId1, uLId1);
                    LoopEdgeItr lItr2 = new LoopEdgeItr(this, hEId2, uLId2);
                    uint        nLV1  = lItr1.GetUseLoopVertexCount();
                    uint        nLV2  = lItr2.GetUseLoopVertexCount();
                    System.Diagnostics.Debug.Assert(nLV1 > 1 && nLV2 > 1);
                    if (nLV1 == 2 || nLV2 == 2)
                    {
                        return(false);
                    }
                }
                uint uVId2 = hE2.UVId;
                System.Diagnostics.Debug.Assert(BRep.IsUseVertexId(uVId2));
                uint removeHEId1 = hEId1;
                if (!BRep.KVE(removeHEId1))
                {
                    System.Diagnostics.Debug.Assert(false);
                }
                System.Diagnostics.Debug.Assert(BRep.AssertValidUse() == 0);
                Edge2HalfEdge.Remove(eId1);
            }
            System.Diagnostics.Debug.Assert(AssertValid());
            return(true);
        }
Exemplo n.º 2
0
 public LoopEdgeItr(LoopEdgeItr src)
 {
     IsValid    = src.IsValid;
     IsInitial  = src.IsInitial;
     IsChildEnd = src.IsChildEnd;
     HEId       = src.HEId;
     ULId       = src.ULId;
     BRep2D.Copy(src.BRep2D);
 }
Exemplo n.º 3
0
        public static LoopEdgeItr operator++(LoopEdgeItr src)
        {
            LoopEdgeItr dest = new LoopEdgeItr(src);

            if (!src.IsValid)
            {
                return(dest);
            }
            dest.IsInitial = false;
            System.Diagnostics.Debug.Assert(dest.BRep2D.BRep.IsHalfEdgeId(dest.HEId));
            HalfEdge hE = dest.BRep2D.BRep.GetHalfEdge(dest.HEId);

            dest.HEId = hE.FHEId;
            return(dest);
        }
Exemplo n.º 4
0
        public bool SwapLoopEdgeItr(LoopEdgeItr lItr, uint toLId)
        {
            uint toParentULId;
            {
                toParentULId = Loop2UseLoop[toLId];
                UseLoop uL = BRep.GetUseLoop(toParentULId);
                System.Diagnostics.Debug.Assert(uL.ParentULId == toParentULId);
            }
            uint fromULId = lItr.GetUseLoopId();

            {
                System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(fromULId));
                UseLoop uL = BRep.GetUseLoop(fromULId);
                System.Diagnostics.Debug.Assert(uL.ParentULId != fromULId);
            }
            BRep.MoveUseLoop(fromULId, toParentULId);
            BRep.SetUseLoopLoopId(fromULId, toLId);
            return(true);
        }
Exemplo n.º 5
0
 public bool IsSameUseLoop(LoopEdgeItr lItr)
 {
     return(lItr.ULId == ULId);
 }
Exemplo n.º 6
0
        public bool MoveLoop(uint lId, OpenTK.Vector2d vecDelta)
        {
            if (!IsElementId(CadElementType.Loop, lId))
            {
                return(false);
            }
            Dictionary <uint, OpenTK.Vector2d> mapOldVec = new Dictionary <uint, OpenTK.Vector2d>();
            HashSet <uint> setLId = new HashSet <uint>();  // check these loop for intersection detection

            for (LoopEdgeItr lItr = this.BRep.GetLoopEdgeItr(lId); !lItr.IsChildEnd; lItr.ShiftChildLoop())
            {
                for (lItr.Begin(); !lItr.IsEnd(); lItr++)
                {
                    uint vId = lItr.GetVertexId();
                    if (mapOldVec.ContainsKey(vId))
                    {
                        continue; // this point is already moved
                    }
                    mapOldVec.Add(vId, GetVertexCoord(vId));
                    Vertex2D vertex = VertexArray.GetObject(vId);
                    {
                        double oldX = vertex.Point.X;
                        double oldY = vertex.Point.Y;
                        vertex.Point = new OpenTK.Vector2d(oldX + vecDelta.X, oldY + vecDelta.Y);
                    }
                    uint eId0;
                    bool isSameDir0;
                    lItr.GetEdgeId(out eId0, out isSameDir0);
                    if (!IsElementId(CadElementType.Edge, eId0))
                    {
                        continue;  // this is point
                    }
                    uint lLId;
                    uint rLId;
                    this.GetEdgeLoopId(out lLId, out rLId, eId0);
                    if (!setLId.Contains(lLId))
                    {
                        setLId.Add(lLId);
                    }
                    if (!setLId.Contains(rLId))
                    {
                        setLId.Add(rLId);
                    }
                }
            }
            foreach (uint lIdl0 in setLId)
            {
                if (!IsElementId(CadElementType.Loop, lIdl0))
                {
                    continue;  // id0 can be 0 if this loop(id_l) have open boundary
                }
                if (CheckLoop(lIdl0) != 0)
                {
                    // fail
                    foreach (var oldVec in mapOldVec)
                    {
                        uint     vId    = oldVec.Key;
                        Vertex2D vertex = VertexArray.GetObject(vId);
                        vertex.Point = oldVec.Value;
                    }
                    return(false);
                }
            }
            return(true);
        }