Пример #1
0
 public static void Store(PolyLine2d polyline, BinaryWriter writer)
 {
     writer.Write(polyline.VertexCount);
     for (int i = 0; i < polyline.VertexCount; ++i)
     {
         writer.Write(polyline[i].x);
         writer.Write(polyline[i].y);
     }
 }
Пример #2
0
 public TubeGenerator(PolyLine2d tubePath, Frame3f pathPlane, Polygon2d tubeShape, int nPlaneNormal = 2)
 {
     Vertices = new List <Vector3d>();
     foreach (Vector2d v in tubePath.Vertices)
     {
         Vertices.Add(pathPlane.FromPlaneUV((Vector2f)v, nPlaneNormal));
     }
     Polygon    = new Polygon2d(tubeShape);
     ClosedLoop = false;
     Capped     = true;
 }
Пример #3
0
        /// <summary>
        /// sequentially insert segments of polyline
        /// </summary>
        public void Insert(PolyLine2d pline, int gid = -1)
        {
            int N = pline.VertexCount - 1;

            for (int i = 0; i < N; ++i)
            {
                Vector2d a = pline[i];
                Vector2d b = pline[i + 1];
                insert_segment(a, b, gid);
            }
        }
Пример #4
0
        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));
            }
        }
Пример #5
0
        static Polygon2d to_loop(PolyLine2d p1, PolyLine2d p2, double eps = MathUtil.Epsilon)
        {
            Polygon2d p = new Polygon2d(p1.Vertices);

            if (p1.End.Distance(p2.Start) > eps)
            {
                p2.Reverse();
            }
            p.AppendVertices(p2);
            return(p);
        }
Пример #6
0
        public void AppendPolyline(PolyLine2d poly, int gid = -1)
        {
            int prev = -1;
            int N    = poly.VertexCount;

            for (int i = 0; i < N; ++i)
            {
                int cur = AppendVertex(poly[i]);
                AppendEdge(prev, cur, gid);
                prev = cur;
            }
        }
Пример #7
0
        public void Add(PolyLine2d pline)
        {
            SmoothCurveElement e = new SmoothCurveElement();

            e.ID     = id_generator++;
            e.source = new PolyLine2DCurve()
            {
                Polyline = pline
            };
            e.polyLine = new PolyLine2d(pline);
            vElements.Add(e);
        }
Пример #8
0
        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);
        }
        private static void MergeAppendPolyline(DGraph2 graph, PolyLine2d polyline, double mergeThreshold, int gid = -1)
        {
            int previousVertexIndex = -1;

            foreach (var vertex in polyline)
            {
                int currentVertexIndex = MergeAppendVertex(graph, vertex, mergeThreshold);
                if (previousVertexIndex != -1)
                {
                    graph.AppendEdge(previousVertexIndex, currentVertexIndex, gid);
                }
                previousVertexIndex = currentVertexIndex;
            }
        }
Пример #10
0
        // returns set of open curves (ie non-solids)
        public OpenCurvesInfo FindOpenCurves(double fSimplifyDeviationTol = 0.1)
        {
            var curveElems = new List <SmoothCurveElement>(CurvesItr());
            int N          = curveElems.Count;

            int maxid = 0;

            foreach (var v in curveElems)
            {
                maxid = Math.Max(maxid, v.ID + 1);
            }

            // copy polygons, simplify if desired
            double fClusterTol   = 0.0;                 // don't do simple clustering, can lose corners
            double fDeviationTol = fSimplifyDeviationTol;
            var    polylines     = new PolyLine2d[maxid];
            var    curves        = new IParametricCurve2d[maxid];

            foreach (var v in curveElems)
            {
                var p = new PolyLine2d(v.polyLine);
                if (fClusterTol > 0 || fDeviationTol > 0)
                {
                    p.Simplify(fClusterTol, fDeviationTol);
                }

                polylines[v.ID] = p;
                curves[v.ID]    = v.source;
            }

            var ci = new OpenCurvesInfo()
            {
                Polylines = new List <PolyLine2d>(),
                Curves    = new List <IParametricCurve2d>()
            };

            for (int i = 0; i < polylines.Length; ++i)
            {
                if (polylines[i] != null && polylines[i].VertexCount > 0)
                {
                    ci.Polylines.Add(polylines[i]);
                    ci.Curves.Add(curves[i]);
                }
            }

            return(ci);
        }
Пример #11
0
        static List <PolyLine2d> find_connected_end(PolyLine2d pTest, List <PolyLine2d> potential, double eps = MathUtil.Epsilon)
        {
            List <PolyLine2d> result = new List <PolyLine2d>();

            foreach (var p in potential)
            {
                if (pTest == p)
                {
                    continue;
                }
                if (pTest.End.Distance(p.Start) < eps ||
                    pTest.End.Distance(p.End) < eps)
                {
                    result.Add(p);
                }
            }
            return(result);
        }
Пример #12
0
        void write_polyline(PolyLine2d poly, StreamWriter w)
        {
            StringBuilder b = new StringBuilder();

            b.Append("<polyline points=\"");
            for (int i = 0; i < poly.VertexCount; ++i)
            {
                b.Append(Math.Round(poly[i].x, Precision));
                b.Append(',');
                b.Append(Math.Round(poly[i].y, Precision));
                if (i < poly.VertexCount - 1)
                {
                    b.Append(' ');
                }
            }
            b.Append("\" ");
            append_style(b, poly, ref DefaultPolylineStyle);
            b.Append(" />");

            w.WriteLine(b);
        }
Пример #13
0
        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);
        }
Пример #14
0
 public void AddPolyline(PolyLine2d poly, Style style)
 {
     Objects.Add(poly);
     Styles[poly] = style;
     Bounds.Contain(poly.Bounds);
 }
Пример #15
0
 public void AddPolyline(PolyLine2d poly)
 {
     Objects.Add(poly);
     Bounds.Contain(poly.Bounds);
 }
Пример #16
0
 public PolyLine2d(PolyLine2d copy)
 {
     vertices  = new List <Vector2d>(copy.vertices);
     Timestamp = 0;
 }
Пример #17
0
 public void AddPolyline(PolyLine2d poly)
 {
     CurrentLayer.Objects.Add(poly);
     Bounds.Contain(poly.Bounds);
 }
Пример #18
0
 public PolySimplification2(PolyLine2d polycurve)
 {
     Vertices = new List <Vector2d>(polycurve.Vertices);
     IsLoop   = false;
 }
Пример #19
0
        /// <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);
        }