Ejemplo n.º 1
0
        public uint GetEdgeCount()
        {
            if (!IsValid)
            {
                return(0);
            }
            System.Diagnostics.Debug.Assert(BRep2D.BRep.IsUseVertexId(UVId));
            UseVertex uV    = BRep2D.BRep.GetUseVertex(UVId);
            uint      hEId0 = uV.HEId;
            uint      hEId  = hEId0;
            uint      iCnt  = 0;

            while (true)
            {
                System.Diagnostics.Debug.Assert(BRep2D.BRep.IsHalfEdgeId(hEId));
                HalfEdge hE = BRep2D.BRep.GetHalfEdge(hEId);
                if (hE.EId == 0)
                {
                    return(0);
                }
                iCnt++;
                uint bHEId = hE.BHEId;
                System.Diagnostics.Debug.Assert(BRep2D.BRep.IsHalfEdgeId(bHEId));
                HalfEdge bHE = BRep2D.BRep.GetHalfEdge(bHEId);
                hEId = bHE.OHEId;
                if (hEId == hEId0)
                {
                    break;
                }
            }
            return(iCnt);
        }
Ejemplo n.º 2
0
        public void Copy(IIdObject src)
        {
            UseVertex srcUV = src as UseVertex;

            Id   = srcUV.Id;
            HEId = srcUV.HEId;
            VId  = srcUV.VId;
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void Begin()
        {
            if (!IsValid)
            {
                return;
            }
            IsInitial = true;
            UseVertex uV = BRep2D.BRep.GetUseVertex(UVId);

            System.Diagnostics.Debug.Assert(uV.Id == UVId);
            HEId = uV.HEId;
        }
Ejemplo n.º 5
0
        public VertexEdgeItr(BRep2D bRep2D, uint vId)
        {
            BRep2D  = bRep2D;
            IsValid = false;
            UVId    = vId;
            UseVertex uV = BRep2D.BRep.GetUseVertex(UVId);

            System.Diagnostics.Debug.Assert(uV.Id == UVId);
            HEId      = uV.HEId;
            IsInitial = true;
            IsValid   = true;
        }
Ejemplo n.º 6
0
        public bool IsEnd()
        {
            if (IsInitial)
            {
                return(false);
            }
            System.Diagnostics.Debug.Assert(BRep2D.BRep.IsUseVertexId(UVId));
            UseVertex uV = BRep2D.BRep.GetUseVertex(UVId);

            if (HEId == uV.HEId)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        public uint GetVertexId()
        {
            if (!IsValid)
            {
                return(0);
            }
            System.Diagnostics.Debug.Assert(BRep2D.BRep.IsHalfEdgeId(HEId));
            HalfEdge hE = BRep2D.BRep.GetHalfEdge(HEId);

            System.Diagnostics.Debug.Assert(BRep2D.BRep.IsUseVertexId(hE.UVId));
            UseVertex uV  = BRep2D.BRep.GetUseVertex(hE.UVId);
            uint      vId = uV.VId;

            System.Diagnostics.Debug.Assert(BRep2D.IsElementId(CadElementType.Vertex, vId));
            return(vId);
        }
Ejemplo n.º 8
0
        public uint GetBehindVertexId()
        {
            if (!IsValid)
            {
                return(0);
            }
            System.Diagnostics.Debug.Assert(BRep2D.BRep.IsHalfEdgeId(HEId));
            HalfEdge hE    = BRep2D.BRep.GetHalfEdge(HEId);
            uint     bHEId = hE.BHEId;

            System.Diagnostics.Debug.Assert(BRep2D.BRep.IsHalfEdgeId(bHEId));
            HalfEdge  bHE   = BRep2D.BRep.GetHalfEdge(bHEId);
            uint      bUVId = bHE.UVId;
            UseVertex bUV   = BRep2D.BRep.GetUseVertex(bUVId);
            uint      vId   = bUV.VId;

            System.Diagnostics.Debug.Assert(BRep2D.IsElementId(CadElementType.Vertex, vId));
            return(vId);
        }
Ejemplo n.º 9
0
        public uint GetAheadVertexId()
        {
            if (!IsValid)
            {
                return(0);
            }
            System.Diagnostics.Debug.Assert(BRep2D.BRep.IsHalfEdgeId(HEId));
            HalfEdge hE    = BRep2D.BRep.GetHalfEdge(HEId);
            uint     fHEId = hE.FHEId;

            System.Diagnostics.Debug.Assert(BRep2D.BRep.IsHalfEdgeId(fHEId));
            HalfEdge  fHE   = BRep2D.BRep.GetHalfEdge(fHEId);
            uint      fUVId = fHE.UVId;
            UseVertex fUV   = BRep2D.BRep.GetUseVertex(fUVId);
            uint      vId   = fUV.VId;

            System.Diagnostics.Debug.Assert(BRep2D.IsElementId(CadElementType.Vertex, vId));
            return(vId);
        }
Ejemplo n.º 10
0
 public UseVertex(UseVertex src)
 {
     Copy(src);
 }
Ejemplo n.º 11
0
        public bool AssertValid()
        {
            foreach (var pair in Loop2UseLoop)
            {
                uint lId        = pair.Key;
                uint parentULId = pair.Value;
                System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(parentULId));
                {
                    UseLoop uL = BRep.GetUseLoop(parentULId);
                    System.Diagnostics.Debug.Assert(uL.Id == parentULId);
                    System.Diagnostics.Debug.Assert(uL.LId == lId);
                }
                System.Diagnostics.Debug.Assert(GetUseLoopType(parentULId) == 2);
                uint uLId = parentULId;
                while (true)
                {
                    System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(uLId));
                    UseLoop uL = BRep.GetUseLoop(uLId);
                    System.Diagnostics.Debug.Assert(uL.Id == uLId);
                    System.Diagnostics.Debug.Assert(uL.LId == lId);
                    System.Diagnostics.Debug.Assert(uL.ParentULId == parentULId);
                    uLId = uL.ChildULId;
                    if (uLId == 0)
                    {
                        break;
                    }
                }
            }

            foreach (var pair in Edge2HalfEdge)
            {
                uint hEId = pair.Value;
                System.Diagnostics.Debug.Assert(BRep.IsHalfEdgeId(hEId));
            }

            IList <uint> uLIds = BRep.UseLoopArray.GetObjectIds();

            for (int i = 0; i < uLIds.Count; i++)
            {
                uint uLId = uLIds[i];
                System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(uLId));
                UseLoop uL = BRep.GetUseLoop(uLId);
                System.Diagnostics.Debug.Assert(uL.Id == uLId);
                uint lId = uL.LId;
                if (lId == 0)
                {
                    System.Diagnostics.Debug.Assert(uL.ParentULId == 0);
                    //2019-03-11 RemoveElement FIX
                    //System.Diagnostics.Debug.Assert(uL.ChildULId == 0);
                    continue;
                }
                System.Diagnostics.Debug.Assert(Loop2UseLoop.ContainsKey(lId));
            }

            IList <uint> hEIds = BRep.HalfEdgeArray.GetObjectIds();

            for (int i = 0; i < hEIds.Count; i++)
            {
                uint hEId = hEIds[i];
                System.Diagnostics.Debug.Assert(BRep.IsHalfEdgeId(hEId));
                HalfEdge hEdge = BRep.GetHalfEdge(hEId);
                System.Diagnostics.Debug.Assert(hEdge.Id == hEId);

                uint vId1;
                {
                    uint uVId1 = hEdge.UVId;
                    System.Diagnostics.Debug.Assert(BRep.IsUseVertexId(uVId1));
                    UseVertex uV = BRep.GetUseVertex(uVId1);
                    System.Diagnostics.Debug.Assert(uV.Id == uVId1);
                    vId1 = uV.VId;
                }

                uint vId2;
                {
                    uint fHEId = hEdge.FHEId;
                    System.Diagnostics.Debug.Assert(BRep.IsHalfEdgeId(fHEId));
                    HalfEdge cwEdge = BRep.GetHalfEdge(fHEId);
                    System.Diagnostics.Debug.Assert(cwEdge.Id == fHEId);
                    System.Diagnostics.Debug.Assert(cwEdge.BHEId == hEId);
                    System.Diagnostics.Debug.Assert(cwEdge.ULId == hEdge.ULId);
                    uint uvId2 = cwEdge.UVId;
                    System.Diagnostics.Debug.Assert(BRep.IsUseVertexId(uvId2));
                    UseVertex uV = BRep.GetUseVertex(uvId2);
                    System.Diagnostics.Debug.Assert(uV.Id == uvId2);
                    vId2 = uV.VId;
                }

                bool isSameDir = hEdge.IsSameDir;
                uint eId       = hEdge.EId;
                if (eId == 0)
                {
                    System.Diagnostics.Debug.Assert(hEdge.OHEId == hEId);
                    System.Diagnostics.Debug.Assert(hEdge.BHEId == hEId);
                    System.Diagnostics.Debug.Assert(hEdge.FHEId == hEId);
                    continue;
                }

                System.Diagnostics.Debug.Assert(Edge2HalfEdge.ContainsKey(eId));

                uint sVId;
                uint eVId;
                GetEdgeVertexIds(eId, out sVId, out eVId);

                if (isSameDir)
                {
                    System.Diagnostics.Debug.Assert(vId1 == sVId);
                    System.Diagnostics.Debug.Assert(vId2 == eVId);
                }
                else
                {
                    System.Diagnostics.Debug.Assert(vId1 == eVId);
                    System.Diagnostics.Debug.Assert(vId2 == sVId);
                }
            }

            IList <uint> uVIds = BRep.UseVertexArray.GetObjectIds();

            for (int i = 0; i < uVIds.Count; i++)
            {
                uint uVId = uVIds[i];
                System.Diagnostics.Debug.Assert(BRep.IsUseVertexId(uVId));
                UseVertex uV = BRep.GetUseVertex(uVId);
                System.Diagnostics.Debug.Assert(uV.Id == uVId);
                uint vId = uV.VId;
                System.Diagnostics.Debug.Assert(uVId == vId);
            }
            return(true);
        }
Ejemplo n.º 12
0
        public bool Serialize(Serializer arch)
        {
            if (arch.IsLoading)
            {   // 読み込み時の処理
                Clear();

                string   className;
                string[] values;

                className = arch.ReadDepthClassName();
                if (className != "BRep2D")
                {
                    return(true);
                }
                {
                    int ne;
                    values = arch.GetValues();
                    ne     = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(ne >= 0);
                    for (uint ie = 0; ie < ne; ie++)
                    {
                        int itmp;
                        int eId;
                        int hEId;
                        values = arch.GetValues();
                        itmp   = int.Parse(values[0]);
                        eId    = int.Parse(values[1]);
                        hEId   = int.Parse(values[2]);
                        Edge2HalfEdge.Add((uint)eId, (uint)hEId);
                    }
                }
                {
                    int nl;
                    values = arch.GetValues();
                    nl     = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(nl >= 0);
                    for (uint il = 0; il < nl; il++)
                    {
                        int itmp;
                        int lId;
                        int uLId;
                        values = arch.GetValues();
                        itmp   = int.Parse(values[0]);
                        lId    = int.Parse(values[1]);
                        uLId   = int.Parse(values[2]);
                        Loop2UseLoop.Add((uint)lId, (uint)uLId);
                    }
                }
                ////////////////
                int nuv;
                int nhe;
                int nul;
                {
                    values = arch.GetValues();
                    nuv    = int.Parse(values[0]);
                    nhe    = int.Parse(values[1]);
                    nul    = int.Parse(values[2]);
                    System.Diagnostics.Debug.Assert(nuv > 0);
                    System.Diagnostics.Debug.Assert(nhe > 0);
                    System.Diagnostics.Debug.Assert(nul > 0);

                    /*
                     * m_BRep.m_UseVertexSet.Reserve(nuv * 2);
                     * m_BRep.m_HalfEdgeSet.Reserve(nhe * 2);
                     * m_BRep.m_UseLoopSet.Reserve(nul * 2);
                     */
                }
                ////////////////////////////////////////////////
                arch.ShiftDepth(true);
                for (int iuv = 0; iuv < nuv; iuv++)
                {
                    className = arch.ReadDepthClassName();
                    System.Diagnostics.Debug.Assert(className == "CUseVertex");

                    int id;
                    values = arch.GetValues();
                    id     = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(id > 0);

                    int vId;
                    values = arch.GetValues();
                    vId    = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(vId > 0);

                    int hEId;
                    values = arch.GetValues();
                    hEId   = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(hEId > 0);

                    UseVertex uv    = new UseVertex((uint)id, (uint)hEId);
                    uint      tmpId = BRep.UseVertexArray.AddObject(uv);
                    System.Diagnostics.Debug.Assert(tmpId == id);
                    BRep.SetUseVertexVertexId((uint)id, (uint)vId);
                }
                for (int ihe = 0; ihe < nhe; ihe++)
                {
                    className = arch.ReadDepthClassName();
                    System.Diagnostics.Debug.Assert(className == "CHalfEdge");

                    int id;
                    values = arch.GetValues();
                    id     = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(id > 0);

                    int eId;
                    values = arch.GetValues();
                    eId    = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(eId >= 0);

                    int iIsSameDir;
                    values     = arch.GetValues();
                    iIsSameDir = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(iIsSameDir >= 0);

                    int uvId;
                    values = arch.GetValues();
                    uvId   = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(uvId > 0);

                    int fHEId;
                    int ccwHEId;
                    int oHEId;
                    values  = arch.GetValues();
                    fHEId   = int.Parse(values[0]);
                    ccwHEId = int.Parse(values[1]);
                    oHEId   = int.Parse(values[2]);
                    System.Diagnostics.Debug.Assert(
                        fHEId > 0 && ccwHEId > 0 && oHEId > 0);

                    int id_ul;
                    values = arch.GetValues();
                    id_ul  = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(id_ul > 0);

                    bool     is_same_dir = (iIsSameDir != 0);
                    HalfEdge he          = new HalfEdge(
                        (uint)id, (uint)uvId, (uint)fHEId, (uint)ccwHEId, (uint)oHEId, (uint)id_ul);
                    uint tmp_id = BRep.HalfEdgeArray.AddObject(he);
                    System.Diagnostics.Debug.Assert(tmp_id == id);
                    BRep.SetHalfEdgeEdgeId((uint)id, (uint)eId, is_same_dir);
                }
                for (int iul = 0; iul < nul; iul++)
                {
                    className = arch.ReadDepthClassName();
                    System.Diagnostics.Debug.Assert(className == "CUseLoop");

                    int id;
                    values = arch.GetValues();
                    id     = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(id > 0);

                    int lId;
                    values = arch.GetValues();
                    lId    = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(lId >= 0);

                    int hEId;
                    values = arch.GetValues();
                    hEId   = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(hEId > 0);

                    int cULId;
                    values = arch.GetValues();
                    cULId  = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(cULId >= 0);

                    int pULId;
                    values = arch.GetValues();
                    pULId  = int.Parse(values[0]);
                    System.Diagnostics.Debug.Assert(pULId >= 0);

                    UseLoop ul    = new UseLoop((uint)id, (uint)hEId, (uint)cULId, (uint)pULId);
                    uint    tmpId = BRep.UseLoopArray.AddObject(ul);
                    System.Diagnostics.Debug.Assert(tmpId == id);
                    BRep.SetUseLoopLoopId((uint)id, (uint)lId);
                }
                arch.ShiftDepth(false);
                AssertValid();
                return(true);
            }
            else
            {
                // 書き込み時の処理
                string line;

                // クラスの名前の指定,サイズの指定
                arch.WriteDepthClassName("BRep2D");
                {
                    line = string.Format("{0}", Edge2HalfEdge.Count);
                    arch.WriteLine(line);

                    uint icnt = 0;
                    foreach (var pair in Edge2HalfEdge)
                    {
                        line = string.Format("{0} {1} {2}", icnt, pair.Key, pair.Value);
                        arch.WriteLine(line);
                        icnt++;
                    }
                }
                {
                    line = string.Format("{0}", Loop2UseLoop.Count);
                    arch.WriteLine(line);

                    uint icnt = 0;
                    foreach (var pair in Loop2UseLoop)
                    {
                        line = string.Format("{0} {1} {2}", icnt, pair.Key, pair.Value);
                        arch.WriteLine(line);
                        icnt++;
                    }
                }

                line = string.Format("{0} {1} {2}",
                                     BRep.UseVertexArray.GetObjectIds().Count,
                                     BRep.HalfEdgeArray.GetObjectIds().Count,
                                     BRep.UseLoopArray.GetObjectIds().Count);
                arch.WriteLine(line);

                arch.ShiftDepth(true);
                ////////////////
                // UseVertexの出力
                {
                    IList <uint> ids = BRep.UseVertexArray.GetObjectIds();
                    foreach (uint uvId in ids)
                    {
                        System.Diagnostics.Debug.Assert(BRep.IsUseVertexId(uvId));
                        UseVertex uv = BRep.GetUseVertex(uvId);
                        System.Diagnostics.Debug.Assert(uv.Id == uvId);

                        arch.WriteDepthClassName("CUseVertex");

                        line = string.Format("{0}", uvId);
                        arch.WriteLine(line);

                        line = string.Format("{0}", uv.VId);
                        arch.WriteLine(line);

                        line = string.Format("{0}", uv.HEId);
                        arch.WriteLine(line);
                    }
                }
                // HalfEdgeの出力
                {
                    IList <uint> ids = BRep.HalfEdgeArray.GetObjectIds();
                    foreach (uint hEId in ids)
                    {
                        System.Diagnostics.Debug.Assert(BRep.IsHalfEdgeId(hEId));
                        HalfEdge he = BRep.GetHalfEdge(hEId);
                        System.Diagnostics.Debug.Assert(he.Id == hEId);

                        arch.WriteDepthClassName("CHalfEdge");

                        line = string.Format("{0}", hEId);
                        arch.WriteLine(line);

                        line = string.Format("{0}", he.EId);
                        arch.WriteLine(line);

                        line = string.Format("{0}", (he.IsSameDir ? 1 : 0));
                        arch.WriteLine(line);

                        line = string.Format("{0}", he.UVId);
                        arch.WriteLine(line);

                        line = string.Format("{0} {1} {2}", he.FHEId, he.BHEId, he.OHEId);
                        arch.WriteLine(line);

                        line = string.Format("{0}", he.ULId);
                        arch.WriteLine(line);
                    }
                }
                // UseLoopの出力
                {
                    IList <uint> ids = BRep.UseLoopArray.GetObjectIds();
                    foreach (uint uLId in ids)
                    {
                        System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(uLId));
                        UseLoop ul = BRep.GetUseLoop(uLId);
                        System.Diagnostics.Debug.Assert(ul.Id == uLId);

                        arch.WriteDepthClassName("CUseLoop");

                        line = string.Format("{0}", uLId);
                        arch.WriteLine(line);

                        line = string.Format("{0}", ul.LId);
                        arch.WriteLine(line);

                        line = string.Format("{0}", ul.HEId);
                        arch.WriteLine(line);

                        line = string.Format("{0}", ul.ChildULId);
                        arch.WriteLine(line);

                        line = string.Format("{0}", ul.ParentULId);
                        arch.WriteLine(line);
                    }
                }
                arch.ShiftDepth(false);
            }
            return(true);
        }