void insert_segment(IntersectSegment seg) { List <int> subfaces = get_all_baseface_tris(seg.base_tid); var op = new RegionOperator(Target, subfaces); Vector3d n = BaseFaceNormals[seg.base_tid]; Vector3d c = BaseFaceCentroids[seg.base_tid]; Vector3d e0, e1; Vector3d.MakePerpVectors(ref n, out e0, out e1); DMesh3 mesh = op.Region.SubMesh; MeshTransforms.PerVertexTransform(mesh, (v) => { v -= c; return(new Vector3d(v.Dot(e0), v.Dot(e1), 0)); }); Vector3d end0 = seg.v0.v, end1 = seg.v1.v; end0 -= c; end1 -= c; var p0 = new Vector2d(end0.Dot(e0), end0.Dot(e1)); var p1 = new Vector2d(end1.Dot(e0), end1.Dot(e1)); var path = new PolyLine2d(); path.AppendVertex(p0); path.AppendVertex(p1); var insert = new MeshInsertUVPolyCurve(mesh, path); insert.Apply(); var cutVerts = new MeshVertexSelection(mesh); cutVerts.SelectEdgeVertices(insert.OnCutEdges); MeshTransforms.PerVertexTransform(mesh, (v) => { return(c + v.x * e0 + v.y * e1); }); op.BackPropropagate(); // add new cut vertices to cut list foreach (int vid in cutVerts) { SegmentInsertVertices.Add(op.ReinsertSubToBaseMapV[vid]); } add_regionop_subfaces(seg.base_tid, op); }
public static void Restore(PolyLine2d polyline, BinaryReader reader) { int count = reader.ReadInt32(); for (int i = 0; i < count; ++i) { double x = reader.ReadDouble(); double y = reader.ReadDouble(); polyline.AppendVertex(new Vector2d(x, y)); } }
static public PolyLine2d MakeBoxSpiral(Vector2d center, double len, double spacing) { double d = spacing / 2; PolyLine2d pline = new PolyLine2d(); pline.AppendVertex(center); Vector2d c = center; c.x += spacing / 2; pline.AppendVertex(c); c.y += spacing; pline.AppendVertex(c); double accum = spacing / 2 + spacing; double w = spacing / 2; double h = spacing; double sign = -1.0; while (accum < len) { w += spacing; c.x += sign * w; pline.AppendVertex(c); accum += w; h += spacing; c.y += sign * h; pline.AppendVertex(c); accum += h; sign *= -1.0; } return(pline); }
/// <summary> /// Decompose graph into simple polylines and polygons. /// </summary> public static Curves ExtractCurves(DGraph2 graph) { Curves c = new Curves(); c.Loops = new List <Polygon2d>(); c.Paths = new List <PolyLine2d>(); HashSet <int> used = new HashSet <int>(); // find boundary and junction vertices HashSet <int> boundaries = new HashSet <int>(); HashSet <int> junctions = new HashSet <int>(); foreach (int vid in graph.VertexIndices()) { if (graph.IsBoundaryVertex(vid)) { boundaries.Add(vid); } if (graph.IsJunctionVertex(vid)) { junctions.Add(vid); } } // walk paths from boundary vertices foreach (int start_vid in boundaries) { int vid = start_vid; int eid = graph.GetVtxEdges(vid)[0]; if (used.Contains(eid)) { continue; } PolyLine2d path = new PolyLine2d(); path.AppendVertex(graph.GetVertex(vid)); while (true) { used.Add(eid); Index2i next = NextEdgeAndVtx(eid, vid, graph); eid = next.a; vid = next.b; path.AppendVertex(graph.GetVertex(vid)); if (boundaries.Contains(vid) || junctions.Contains(vid)) { break; // done! } } c.Paths.Add(path); } // ok we should be done w/ boundary verts now... boundaries.Clear(); foreach (int start_vid in junctions) { foreach (int outgoing_eid in graph.VtxEdgesItr(start_vid)) { if (used.Contains(outgoing_eid)) { continue; } int vid = start_vid; int eid = outgoing_eid; PolyLine2d path = new PolyLine2d(); path.AppendVertex(graph.GetVertex(vid)); while (true) { used.Add(eid); Index2i next = NextEdgeAndVtx(eid, vid, graph); eid = next.a; vid = next.b; path.AppendVertex(graph.GetVertex(vid)); if (eid == int.MaxValue || junctions.Contains(vid)) { break; // done! } } c.Paths.Add(path); } } // all that should be left are continuous loops... foreach (int start_eid in graph.EdgeIndices()) { if (used.Contains(start_eid)) { continue; } int eid = start_eid; Index2i ev = graph.GetEdgeV(eid); int vid = ev.a; Polygon2d poly = new Polygon2d(); poly.AppendVertex(graph.GetVertex(vid)); while (true) { used.Add(eid); Index2i next = NextEdgeAndVtx(eid, vid, graph); eid = next.a; vid = next.b; poly.AppendVertex(graph.GetVertex(vid)); if (eid == int.MaxValue || junctions.Contains(vid)) { throw new Exception("how did this happen??"); } if (used.Contains(eid)) { break; } } poly.RemoveVertex(poly.VertexCount - 1); c.Loops.Add(poly); } return(c); }