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); }
public bool RemoveEdge(uint eId, bool isDelCP) { uint hEId1 = 0; { if (!Edge2HalfEdge.ContainsKey(eId)) { return(false); } hEId1 = Edge2HalfEdge[eId]; } uint hEId2; { System.Diagnostics.Debug.Assert(BRep.IsHalfEdgeId(hEId1)); HalfEdge hE1 = BRep.GetHalfEdge(hEId1); hEId2 = hE1.OHEId; } uint uLId1; uint lId1; bool isEdgeVertex2 = false; { HalfEdge hE1 = BRep.GetHalfEdge(hEId1); System.Diagnostics.Debug.Assert(hE1.OHEId == hEId2); uLId1 = hE1.ULId; UseLoop uL1 = BRep.GetUseLoop(uLId1); lId1 = uL1.LId; if (hE1.FHEId == hEId2) { isEdgeVertex2 = true; } } uint uLId2; uint lId2; bool isEdgeVertex1 = false; { HalfEdge hE2 = BRep.GetHalfEdge(hEId2); System.Diagnostics.Debug.Assert(hE2.OHEId == hEId1); uLId2 = hE2.ULId; UseLoop uL2 = BRep.GetUseLoop(uLId2); lId2 = uL2.LId; if (hE2.FHEId == hEId1) { isEdgeVertex1 = true; } } if (lId1 != lId2) { System.Diagnostics.Debug.Assert(uLId1 != uLId2); System.Diagnostics.Debug.Assert(!isEdgeVertex1 && !isEdgeVertex2); uint newLId; if (lId1 != 0) { if (lId2 == 0) { newLId = 0; } else { newLId = lId1; } } else { newLId = 0; } { uint uLId = uLId1; UseLoop uL = BRep.GetUseLoop(uLId); uLId = uL.ParentULId; while (true) { if (uLId == 0) { break; } BRep.SetUseLoopLoopId(uLId, newLId); System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(uLId)); UseLoop tmpUL = BRep.GetUseLoop(uLId); uLId = tmpUL.ChildULId; } } { uint uLId = uLId2; UseLoop uL = BRep.GetUseLoop(uLId); uLId = uL.ParentULId; while (true) { if (uLId == 0) { break; } BRep.SetUseLoopLoopId(uLId, newLId); System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(uLId)); UseLoop tmpUL = BRep.GetUseLoop(uLId); uLId = tmpUL.ChildULId; } } if (lId1 != 0) { if (!BRep.KEL(hEId1)) { System.Diagnostics.Debug.Assert(false); } if (lId2 == 0) { Loop2UseLoop.Remove(lId1); } else { Loop2UseLoop.Remove(lId1); Loop2UseLoop.Remove(lId2); System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(uLId1)); UseLoop uL = BRep.GetUseLoop(uLId1); System.Diagnostics.Debug.Assert(BRep.IsUseLoopId(uL.ParentULId)); Loop2UseLoop.Add(lId1, uL.ParentULId); } } else { System.Diagnostics.Debug.Assert(lId2 != 0); if (!BRep.KEL(hEId2)) { System.Diagnostics.Debug.Assert(false); } Loop2UseLoop.Remove(lId2); } Edge2HalfEdge.Remove(eId); System.Diagnostics.Debug.Assert(AssertValid()); return(true); } if (uLId1 == uLId2) { System.Diagnostics.Debug.Assert(lId1 == lId2); if (!isEdgeVertex1 && !isEdgeVertex2) { if (lId1 != 0) { uint addULId; if (!BRep.KEML(out addULId, hEId1)) { System.Diagnostics.Debug.Assert(false); } if (isDelCP) { System.Diagnostics.Debug.Assert(GetUseLoopType(addULId) == 2); if (!BRep.SwapUseLoop(addULId, uLId1)) { System.Diagnostics.Debug.Assert(false); } Loop2UseLoop[lId1] = addULId; } BRep.SetUseLoopLoopId(addULId, lId1); } else { uint addULId; if (!BRep.KEML(out addULId, hEId1)) { System.Diagnostics.Debug.Assert(false); } BRep.SetUseLoopLoopId(addULId, 0); } } else if (isEdgeVertex1 && isEdgeVertex2) { uint addULId; if (!BRep.KEMLTwoFloatingVertex(out addULId, hEId1)) { System.Diagnostics.Debug.Assert(false); } BRep.SetHalfEdgeEdgeId(hEId1, 0, true); BRep.SetHalfEdgeEdgeId(hEId2, 0, true); BRep.SetUseLoopLoopId(addULId, lId1); } else if (isEdgeVertex1 && !isEdgeVertex2) { uint id_ul_add; if (!BRep.KEMLOneFloatingVertex(out id_ul_add, hEId1)) { System.Diagnostics.Debug.Assert(false); } BRep.SetUseLoopLoopId(id_ul_add, lId1); } else if (isEdgeVertex2 && !isEdgeVertex1) { uint id_ul_add; if (!BRep.KEMLOneFloatingVertex(out id_ul_add, hEId2)) { System.Diagnostics.Debug.Assert(false); } BRep.SetUseLoopLoopId(id_ul_add, lId1); } Edge2HalfEdge.Remove(eId); System.Diagnostics.Debug.Assert(AssertValid()); return(true); } return(false); }
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); }