private LINE AddLine(PO p1, PO p2, PO px) { //在p1和p2之间添加一条边,px用于确定p1-p2需要失效的方向,并返回新生成的边 //create the info for k1 and k2 util u1 = new util(); LINE ln0 = new LINE(p1, p2); PAINT.GetLL(ln0); Set_direction(ln0, px); //put ln0 into k1 if (p1.non_merged) { if (p1.ll.Head == null) { p1.ll.Insert(ln0); } else if (p1.ll.Last.Data.p1 == px || p1.ll.Last.Data.p2 == px) { p1.ll.Insert(ln0); } else { p1.ll.Head_Insert(ln0); } } //put ln0 into k2 if (p2.non_merged) { if (p2.ll.Head == null) { p2.ll.Insert(ln0); } else if (p2.ll.Last.Data.p1 == px || p2.ll.Last.Data.p2 == px) { p2.ll.Insert(ln0); } else { p2.ll.Head_Insert(ln0); } } return(ln0); }
public void Initial(model3d m) { //m从生成某个模型的点集中获取包含一个初始面的点集 util u1 = new util(); SURFACE s; PO p0, p1, p2; LINE l1, l2, l3; //获取初始面的三个顶点和一个初始面 p0 = m.pi; p1 = m.pj; p2 = m.pk; s = New_SURFACE(p0, p1, p2); //加入初始的点,构成初始点集 work_pl.Insert(p0); work_pl.Insert(p1); work_pl.Insert(p2); //产生初始面的三个边 l1 = new LINE(p0, p1); l2 = new LINE(p0, p2); l3 = new LINE(p1, p2); //将三条边加到面中 s.l1 = l1; s.l2 = l2; s.l3 = l3; //为每个边加入初始的面集 l1.sl.Insert(s); l2.sl.Insert(s); l3.sl.Insert(s); //为每个点加入初始的边集 p0.ll.Insert(l1); p0.ll.Insert(l2); p1.ll.Insert(l1); p1.ll.Insert(l3); p2.ll.Insert(l2); p2.ll.Insert(l3); pl = m.Get_get_p_l(); //获取模型的点数据,为一个点链 sl.Insert(s); PAINT.GetLL(l1); PAINT.GetLL(l2); PAINT.GetLL(l3); }
private void Insert1() { util u1 = new util(); LINE l0 = nt_current.Data; pg.ToPrint(info); /*获取线链的头边和尾边的外端点*/ PO PLa, PFa; if (pkey.IsEqualToMe(l0.p1)) { PLa = l0.p2; } else { PLa = l0.p1; } if (pkey.IsEqualToMe(pre_l.Head.Data.p1)) { PFa = pre_l.Head.Data.p2; } else { PFa = pre_l.Head.Data.p1; } if (pg.selected) { info.Insert("po selected"); } else { info.Insert("po not selected"); } LINE lt;//获取相应边 info.Insert("t4"); #region PLa-PFa已存在 //如果PLa-PFa已存在,且尾边位于首边未搜索侧或首边两侧都搜索过 lt = Is_OutSide(PLa, PFa); if (lt != null) { info.Insert("ok"); } if (lt != null && (u1.noSearched(pre_l.Head.Data, PLa) || !pre_l.Head.Data.positive && !pre_l.Head.Data.negtive) && pkey.key != 3) { info.Insert("t1"); pkey.non_merged = false; Set_direction(pre_l.Head.Data, PLa); Set_direction(pre_l.Last.Data, PFa); Set_direction(lt, pkey); nt_current = nt_current.Next; // u1.InFile(u1.tri_num, (numbertri++).ToString() + '\t' + pkey.number + '\t' + PLa.number + '\t' + PFa.number); return; } #endregion //后面的没有PLa-PFa已存在的情况 #region pg位于其已搜索侧 if (!u1.noSearched(pre_l.Head.Data, pg) && u1.noSearched(pre_l.Head.Data, PLa) || pg == PFa) { //pg是当前边首边的外端点 info.Insert("t3"); pkey.non_merged = false; Set_direction(pre_l.Head.Data, PLa); Set_direction(l0, PFa); AddLine(PFa, PLa, pkey); nt_current = nt_current.Next; return; //u1.InFile(u1.tri_num, (numbertri++).ToString() + '\t' + pkey.number + '\t' + PLa.number + '\t' + PFa.number); } #endregion if (pg.selected) { //如果pg已经被选过 #region delete shadowpo //当前被处理的点的影子点位于pg的边链上 LINE shadow_l = Is_OutSide(pg, pkey); if (shadow_l != null) { info.Insert("shadow_pg_side"); PO shadow_po = shadow_l.getanotherpo(pg); PO shadow_po1, shadow_po2, shadow_pokey; shadow_po1 = shadow_po.ll.Head.Data.getanotherpo(shadow_po); shadow_po2 = shadow_po.ll.Last.Data.getanotherpo(shadow_po); float shadow_ang1, shadow_ang2; shadow_pokey = shadow_po1; shadow_ang1 = u1.d2_Cal_Op_Angle(PLa, shadow_po1, pkey); shadow_ang2 = u1.d2_Cal_Op_Angle(PLa, shadow_po2, pkey); if (shadow_ang2 < shadow_ang1) { shadow_pokey = shadow_po2; } lt = Is_OutSide(shadow_pokey, PLa); if (lt == null) { lt = AddLine(shadow_pokey, PLa, shadow_po); } PAINT.GetLL(lt); shadowPO(shadow_po, shadow_pokey, pkey, PLa); nt_current = pkey.ll.Last; return; } #endregion #region last's outside //如果pg是last的边链的外端点 lt = Is_OutSide(PLa, pg); if (lt != null) { info.Insert("last's outside\n"); Set_direction(pre_l.Last.Data, pg); AddLine(pkey, pg, PLa); //以上两句代码的顺序不能反,否则会出错 Set_direction(lt, pkey); nt_current = nt_current.Next; return; } #endregion last'soutside #region shadow_deal #region create shadowpo //如果pg是非特殊位置 info.Insert("arbitrary POint\n"); PO pt = new PO(pg.x, pg.y, pg.z); if (pg.shadow_pl != null) { pg.shadow_pl.Insert(pt); } else { info.Insert("add new shadow po\n"); pg.shadow_pl = new LinkList <PO>(); pg.shadow_pl.Insert(pg); pg.shadow_pl.Insert(pt); } pt.shadow_pl = pg.shadow_pl; pg = pt; //u1.InFile(u1.infopath, "here1"); AddLine(pkey, pg, PLa); // u1.InFile(u1.infopath, "here2"); AddLine(PLa, pg, pkey); //u1.InFile(u1.infopath, "here3"); Set_direction(l0, pg); // u1.InFile(u1.infopath, "here4"); //u1.InFile(u1.tri_num, (numbertri++).ToString() + '\t' + pkey.number + '\t' + PLa.number + '\t' + pg.number); work_pl.Insert(pg); //u1.InFile(u1.infopath,"here5"); pg.selected = true; nt_current = nt_current.Next; #endregion #endregion } else { #region ordinary_po info.Insert("ordinary point" + pg.number); //pg作为普通点处理 pg.number = number++; pg.selected = true; //u1.InFile(u1.node_key, pg.number.ToString() + '\t' + pg.x + '\t' + pg.y + '\t' + pg.key); AddLine(pkey, pg, PLa); AddLine(PLa, pg, pkey); Set_direction(l0, pg); //u1.InFile(u1.tri_num, (numbertri++).ToString() + '\t' + pkey.number + '\t' + PLa.number + '\t' + pg.number); if (pg.key != 3) { work_pl.Insert(pg); } //work_pl.Dispaly(); nt_current = nt_current.Next; #endregion } }