Example #1
0
        public virtual void NextSubpath_Int_Int_Bool()
        {
            GraphicsPath path = new GraphicsPath();

            path.AddLine(new Point(100, 100), new Point(400, 100));
            path.AddLine(new Point(400, 200), new Point(10, 100));
            path.StartFigure();
            path.SetMarkers();
            path.AddBezier(10, 10, 50, 250, 100, 5, 200, 280);
            path.CloseFigure();
            path.StartFigure();
            path.SetMarkers();
            path.AddRectangle(new Rectangle(10, 20, 300, 400));
            path.StartFigure();
            path.SetMarkers();
            path.AddLine(new Point(400, 400), new Point(400, 10));

            GraphicsPathIterator iterator = new GraphicsPathIterator(path);

            int  start;
            int  end;
            bool isClosed;

            int count = iterator.NextSubpath(out start, out end, out isClosed);

            Assert.AreEqual(4, count);
            Assert.AreEqual(0, start);
            Assert.AreEqual(3, end);
            Assert.IsFalse(isClosed);

            count = iterator.NextSubpath(out start, out end, out isClosed);
            Assert.AreEqual(4, count);
            Assert.AreEqual(4, start);
            Assert.AreEqual(7, end);
            Assert.IsTrue(isClosed);

            count = iterator.NextSubpath(out start, out end, out isClosed);
            Assert.AreEqual(4, count);
            Assert.AreEqual(8, start);
            Assert.AreEqual(11, end);
            Assert.IsTrue(isClosed);

            count = iterator.NextSubpath(out start, out end, out isClosed);
            Assert.AreEqual(2, count);
            Assert.AreEqual(12, start);
            Assert.AreEqual(13, end);
            Assert.IsFalse(isClosed);

            count = iterator.NextSubpath(out start, out end, out isClosed);
            Assert.AreEqual(0, count);
            Assert.AreEqual(0, start);
            Assert.AreEqual(0, end);
            Assert.IsTrue(isClosed);
        }
Example #2
0
        public static List <List <IntPoint> > ConvertToClipperPolygons(GraphicsPath path)
        {
            var Polygon  = new List <IntPoint>();
            var Polygons = new List <List <IntPoint> >();

            var it = new GraphicsPathIterator(path);

            it.Rewind();
            for (int i = 0; i < it.SubpathCount; i++)
            {
                bool isClosed;
                int  startIndex;
                int  endIndex;
                it.NextSubpath(out startIndex, out endIndex, out isClosed);
                Polygon.AddRange(
                    path.PathPoints
                    .Skip(startIndex)
                    .Take((endIndex - startIndex) + 1)
                    .Select(x => new IntPoint(Convert.ToInt64(x.X * Scale), Convert.ToInt64(x.Y * Scale)))
                    );
                Polygons.Add(new List <IntPoint>(Polygon));
                Polygon.Clear();
            }
            it.Dispose();
            return(Polygons);
        }
Example #3
0
        public void DrawStep(Graphics graphics, Font font, string word, int[] order)
        {
            var isClosed = false;
            var pen      = new Pen(Color.Red);
            var brush    = new SolidBrush(Color.Black);
            var path     = new GraphicsPath();
            var subPath  = new GraphicsPath();

            path.AddString(word, font.FontFamily, (int)font.Style, font.Size, new PointF(0, 0),
                           StringFormat.GenericDefault);
            var iterator = new GraphicsPathIterator(path);
            var rect     = path.GetBounds();

            graphics.PageUnit      = font.Unit;
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            DrawGrid(graphics, rect);
            graphics.DrawPath(pen, path);

            for (var i = 0; i < iterator.SubpathCount; i++)
            {
                Thread.Sleep(1000);
                iterator.Rewind();
                for (var j = 0; j < order[i]; j++)
                {
                    iterator.NextSubpath(subPath, out isClosed);
                }
                graphics.FillPath(brush, subPath);
            }
        }
Example #4
0
        /// <summary>
        /// Renders the flattened path to the device using the specified color.
        /// </summary>
        /// <param name="device">The device to use for rendering the path.</param>
        /// <param name="color">The color to use for the vertices.</param>
        /// <param name="flattenedPath">The path to render.</param>
        protected virtual void Render(Device device, int color, GraphicsPath flattenedPath)
        {
            PointF[] points = flattenedPath.PathPoints;
            device.VertexFormat = CustomVertex.PositionColored.Format;

            bool isClosed;
            GraphicsPathIterator pi = new GraphicsPathIterator(flattenedPath);

            while (pi.NextSubpath(flattenedPath, out isClosed) != 0)
            {
                byte type;
                int  start, end;

                while (pi.NextPathType(out type, out start, out end) != 0)
                {
                    int numDistinctPoints = end - start + 1;
                    int totNumPoints      = numDistinctPoints;
                    if (isClosed)
                    {
                        totNumPoints++;
                    }

                    CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[totNumPoints];
                    P3Util.CreateColoredVertexList(colVerts, points, start, 0, numDistinctPoints, color);

                    if (isClosed)
                    {
                        colVerts[numDistinctPoints] = colVerts[0];
                    }

                    device.DrawUserPrimitives(PrimitiveType.LineStrip, totNumPoints - 1, colVerts);
                }
            }
        }
        public DrawableMulti ToMultiPolygon(bool disposePath = true)
        {
            DrawableMulti multi = new DrawableMulti();

            if (Path == null)
            {
                return(null);
            }

            using (GraphicsPathIterator iterator = new GraphicsPathIterator(Path)) {
                GraphicsPath subpath = new GraphicsPath();
                bool         closed;
                while (iterator.NextSubpath(subpath, out closed) != 0)
                {
                    DrawablePolygon shape = new DrawablePolygon {
                        Points    = subpath.PathPoints,
                        Brush     = Brush,
                        Pen       = Pen,
                        PenClosed = closed
                    };
                    multi.Shapes.Add(shape);
                }
                subpath.Dispose();
            }

            if (disposePath)
            {
                Path?.Dispose();
            }

            return(multi);
        }
Example #6
0
        public Analyzer(double meanX, double meanY, GraphicsPath path)
        {
            Counters = new RunningCount[Enum.GetValues(typeof(AnalysisMetric)).Length];

            foreach (AnalysisMetric metric in Enum.GetValues(typeof(AnalysisMetric)))
            {
                Counters[(int)metric] = new RunningCount(metric);
            }


            MeanX = meanX;
            MeanY = meanY;


            path.Flatten();

            using (GraphicsPathIterator PathIterator = new GraphicsPathIterator(path))
            {
                using (GraphicsPath Subpath = new GraphicsPath())
                {
                    Paths = new List <PointF[]>();

                    bool Closed;

                    while (PathIterator.NextSubpath(Subpath, out Closed) > 0)
                    {
                        Paths.Add(Subpath.PathPoints);
                        Subpath.Reset();
                    }
                }
            }
        }
        public DrawableMulti ToMulti(MultiGen cb, bool disposePath = true)
        {
            DrawableMulti multi = new DrawableMulti();

            if (Path == null)
            {
                return(null);
            }

            using (GraphicsPathIterator iterator = new GraphicsPathIterator(Path)) {
                GraphicsPath subpath = new GraphicsPath();
                bool         closed;
                int          i = 0;
                while (iterator.NextSubpath(subpath, out closed) != 0)
                {
                    Drawable shape = cb(i++, subpath, Brush, Pen, closed);
                    if (shape != null)
                    {
                        multi.Shapes.Add(shape);
                    }
                }
                subpath.Dispose();
            }

            if (disposePath)
            {
                Path?.Dispose();
            }

            return(multi);
        }
Example #8
0
        /// <summary>
        /// Cache a flattened path.
        /// </summary>
        /// <param name="flattenedPath">The flattened path to cache.</param>
        protected virtual void CacheFlatPath(GraphicsPath flattenedPath)
        {
            bool isClosed;
            GraphicsPathIterator pi = new GraphicsPathIterator(flattenedPath);

            PointF[] points = flattenedPath.PathPoints;

            while (pi.NextSubpath(flattenedPath, out isClosed) != 0)
            {
                byte type;
                int  start, end;
                int  oldCount = renderList.Count;

                while (pi.NextPathType(out type, out start, out end) != 0)
                {
                    for (int i = start; i <= end; i++)
                    {
                        renderList.Add(points[i]);
                    }

                    if (isClosed)
                    {
                        renderList.Add(points[start]);
                    }

                    renderListTypes.Add(new PrimitiveTypeInfo(oldCount, renderList.Count - 1, pen.Color.ToArgb(), PrimitiveType.LineStrip));
                }
            }
        }
        public void DrawPath(Color black, GraphicsPath path, float v)
        {
            GraphicsPathIterator pathIterator = new GraphicsPathIterator(path);


            //Rewind
            // pathIterator.Rewind();

            // Read all subpaths and their properties
            for (int i = 0; i < pathIterator.SubpathCount; i++)
            {
                int  strIdx, endIdx;
                bool bClosedCurve;


                pathIterator.NextSubpath(out strIdx, out endIdx, out bClosedCurve);

                for (int j = strIdx; j < endIdx - 1; j++)
                {
                    DrawLine(new Pen(black, v), path.PathPoints[j], path.PathPoints[j + 1]);
                }

                if (bClosedCurve)
                {
                    DrawLine(new Pen(black, v), path.PathPoints[endIdx - 1], path.PathPoints[strIdx]);
                }
            }
        }
Example #10
0
        // </snippet5>


        // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextPathType(System.Byte@,System.Int32@,System.Int32@)
        // <snippet6>
        public void NextPathTypeExample(PaintEventArgs e)
        {
            // Create the GraphicsPath.
            GraphicsPath myPath = new GraphicsPath();

            Point[]   myPoints = { new Point(20,  20), new Point(120, 120),
                                   new Point(20,   120), new Point(20, 20) };
            Rectangle myRect = new Rectangle(120, 120, 100, 100);

            // Add 3 lines, a rectangle, and an ellipse.
            myPath.AddLines(myPoints);
            myPath.AddRectangle(myRect);
            myPath.AddEllipse(220, 220, 100, 100);

            // List all of the path points to the screen.
            ListPathPoints(e, myPath, null, 20, 1);

            // Create a GraphicsPathIterator.
            GraphicsPathIterator myPathIterator = new
                                                  GraphicsPathIterator(myPath);

            // Rewind the Iterator.
            myPathIterator.Rewind();

            // Iterate the subpaths and types, and list the results to

            // the screen.
            int        i, j = 20;
            int        mySubPaths, subPathStartIndex, subPathEndIndex;
            Boolean    IsClosed;
            byte       subPathPointType;
            int        pointTypeStartIndex, pointTypeEndIndex, numPointsFound;
            Font       myFont  = new Font("Arial", 8);
            SolidBrush myBrush = new SolidBrush(Color.Black);

            j = 20;
            for (i = 0; i < 3; i++)
            {
                mySubPaths = myPathIterator.NextSubpath(
                    out subPathStartIndex,
                    out subPathEndIndex,
                    out IsClosed);
                numPointsFound = myPathIterator.NextPathType(
                    out subPathPointType,
                    out pointTypeStartIndex,
                    out pointTypeEndIndex);
                e.Graphics.DrawString(
                    "SubPath: " + i +
                    "  Points Found: " + numPointsFound.ToString() +
                    "  Type of Points: " + subPathPointType.ToString(),
                    myFont,
                    myBrush,
                    200,
                    j);
                j += 20;
            }

            // List the total number of path points to the screen.
            ListPathPoints(e, myPath, myPathIterator, 200, 2);
        }
        public void DrawPath(Color color, GraphicsPath path, float v)
        {
            GraphicsPathIterator pathIterator = new GraphicsPathIterator(path);


            //Rewind
            // pathIterator.Rewind();
            GL.LineWidth(v);
            // Read all subpaths and their properties
            for (int i = 0; i < pathIterator.SubpathCount; i++)
            {
                int  strIdx, endIdx;
                bool bClosedCurve;


                pathIterator.NextSubpath(out strIdx, out endIdx, out bClosedCurve);
                GL.Begin(PrimitiveType.LineStrip);
                GL.Color4(color.R, color.G, color.B, color.A);
                for (int j = strIdx; j < endIdx; j++)
                {
                    GL.Vertex2(path.PathPoints[j].X, path.PathPoints[j].Y);
                }

                if (bClosedCurve)
                {
                    GL.Vertex2(path.PathPoints[strIdx].X, path.PathPoints[strIdx].Y);
                }
                GL.End();
            }
        }
Example #12
0
        public static void DrawStep(Graphics graphics, Font font, string word, int[] order)
        {
            var isClosed = false;
            var pen      = new Pen(Color.Red);
            var brush    = new SolidBrush(Color.Black);
            var subPath  = new GraphicsPath();
            var path     = GetPath(font, word);
            var rect     = path.GetBounds();

            graphics.PageUnit      = font.Unit;
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            DrawGrid(graphics, rect);
            graphics.DrawPath(pen, path);

            var iterator = new GraphicsPathIterator(path);

            for (var i = 0; i < iterator.SubpathCount; i++)
            {
                Thread.Sleep(1000);
                iterator.Rewind();
                for (var j = 0; j < order[i]; j++)
                {
                    iterator.NextSubpath(subPath, out isClosed);
                }
                graphics.FillPath(brush, subPath);
            }
        }
 public void NextSubpath_NullPath_ReturnsExpected()
 {
     using (GraphicsPathIterator gpi = new GraphicsPathIterator(null))
     {
         Assert.Equal(0, gpi.NextSubpath(null, out bool isClosed));
         Assert.False(isClosed);
     }
 }
 public void NextSubpath_PathFigureClosed_ReturnsExpected()
 {
     using (GraphicsPath gp = new GraphicsPath(_twoPoints, new byte[] { 0, 129 }))
         using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
         {
             Assert.Equal(2, gpi.NextSubpath(gp, out bool isClosed));
             Assert.True(isClosed);
         }
 }
Example #15
0
        /// <summary>
        /// Warps one path to the flattened (<see cref="GraphicsPath.Flatten()"/>) version of another path.
        /// This comes in handy for
        /// <list type="Bullet">
        /// <item>Linestyles that cannot be created with available <see cref="Pen"/>-properties</item>
        /// <item>Warping Text to curves</item>
        /// <item>...</item>
        /// </list>
        /// </summary>
        /// <param name="pathToWarpTo">The path to warp to. This path is flattened before being used, so there is no need to call <see cref="GraphicsPath.Flatten()"/> prior to this function call.</param>
        /// <param name="pathToWarp">The path to warp</param>
        /// <param name="isPattern">Defines whether <paramref name="pathToWarp"/> is a pattern or not. If <paramref name="pathToWarp"/> is a pattern, it is repeated until it has the total length of <see paramref="pathToWarpTo"/></param>
        /// <param name="interval">The interval in which the pattern should be repeated</param>
        /// <returns>Warped <see cref="GraphicsPath"/></returns>
        /// <exception cref="ArgumentNullException">If either pathToWarpTo or pathToWarp is null</exception>
        public static GraphicsPath Warp(GraphicsPath pathToWarpTo, GraphicsPath pathToWarp, bool isPattern, float interval)
        {
            //Test for valid arguments
            if (pathToWarpTo == null)
            {
                throw new ArgumentNullException("pathToWarpTo");
            }
            if (pathToWarp == null)
            {
                throw new ArgumentNullException("pathToWarp");
            }

            //Remove all curves from path to warp to, get total length.
            SortedList <float, GraphSegment> edges;

            pathToWarpTo.Flatten();
            Double pathLength = GetPathLength(pathToWarpTo, out edges);

            if (pathLength == 0)
            {
                return(pathToWarp);
            }

            //Prepare path to warp
            pathToWarp = PreparePathToWarp(pathToWarp, isPattern, pathLength, interval);
            if (pathToWarp == null || pathToWarp.PointCount == 0)
            {
                return(null);
            }
            GraphicsPath warpedPath = new GraphicsPath(pathToWarp.FillMode);

            using (GraphicsPathIterator iter = new GraphicsPathIterator(pathToWarp))
            {
                GraphicsPath subPath      = new GraphicsPath();
                int          currentIndex = 0;
                if (iter.SubpathCount > 1)
                {
                    bool isClosed;
                    while (iter.NextSubpath(subPath, out isClosed) > 0)
                    {
                        GraphicsPath warpedSubPath = WarpSubpath(subPath, edges, ref currentIndex);
                        if (isClosed)
                        {
                            warpedSubPath.CloseFigure();
                        }
                        warpedPath.AddPath(warpedSubPath, true);
                        warpedPath.SetMarkers();
                    }
                }
                else
                {
                    warpedPath = WarpSubpath(pathToWarp, edges, ref currentIndex);
                }
            }
            return(warpedPath);
        }
 public void NextSubpath_PathFigureNotClosed_ReturnsExpected()
 {
     using (GraphicsPath gp = new GraphicsPath())
         using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
         {
             gp.AddLines(_twoPoints);
             Assert.Equal(0, gpi.NextSubpath(gp, out bool isClosed));
             Assert.False(isClosed);
         }
 }
Example #17
0
 public void NextSubpath_Null()
 {
     using (GraphicsPath gp = new GraphicsPath()) {
         gp.AddLines(pts_2f);
         using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) {
             bool closed;
             Assert.AreEqual(0, gpi.NextSubpath(null, out closed));
             Assert.IsTrue(closed, "Closed");
         }
     }
 }
Example #18
0
        /// <summary>
        /// Tesselates the specified path, notifying the
        /// <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor">TesselationVisitor</see>
        /// as each new triangle primitive is added.
        /// </summary>
        /// <param name="path">The path to tesselate.</param>
        /// <param name="visitor">The tesselation visitor to notify.</param>
        public virtual void Tesselate(GraphicsPath path, TesselationVisitor visitor)
        {
            this.visitor = visitor;

            switch (path.FillMode)
            {
            case FillMode.Alternate:                     //even/odd
                P3Util.SetWindingRule(tess, P3Util.GlTessWinding.WindingOdd);
                break;

            case FillMode.Winding:                     //nonzero
                P3Util.SetWindingRule(tess, P3Util.GlTessWinding.WindingNonzero);
                break;
            }

            P3Util.GluTessBeginPolygon(tess, IntPtr.Zero);

            bool isClosed;
            GraphicsPathIterator pi = new GraphicsPathIterator(path);

            PointF[] points = path.PathPoints;

            while (pi.NextSubpath(path, out isClosed) != 0)
            {
                byte type;
                int  start, end;
                while (pi.NextPathType(out type, out start, out end) != 0)
                {
                    PathPointType ppType = (PathPointType)type;

                    P3Util.GluTessBeginContour(tess);

                    for (int i = start; i <= end; i++)
                    {
                        PointF   point  = points[i];
                        double[] coords = new double[3];
                        coords[0] = point.X;
                        coords[1] = point.Y;
                        coords[2] = 0;
                        GCHandle handle = GCHandle.Alloc(coords, GCHandleType.Pinned);
                        P3Util.GluTessVertex(tess, coords, (IntPtr)handle);
                        handles.Add(handle);
                    }

                    P3Util.GluTessEndContour(tess);
                }
            }

            P3Util.GluTessEndPolygon(tess);

            ClearHandles();
        }
Example #19
0
        private void SetMarks(GraphicsPath path)
        {
            path.Reset();
            path.AddRectangle(new RectangleF(50, 50, 100, 100));
            path.CloseFigure();
            //path.AddRectangle(new RectangleF(50, 50, 50, 50));
            path.AddLine(new PointF(100, 50), new PointF(100, 150));
            path.CloseFigure();
            path.AddLine(new PointF(50, 100), new PointF(150, 100));
            //path.CloseFigure();
            bool isClosed;

            using (GraphicsPathIterator iter = new GraphicsPathIterator(path))
            {
                GraphicsPath path1 = new GraphicsPath();
                GraphicsPath path2 = new GraphicsPath();
                GraphicsPath path3 = new GraphicsPath();
                iter.NextSubpath(path1, out isClosed);
                iter.NextSubpath(path2, out isClosed);
                iter.NextSubpath(path3, out isClosed);
            }
        }
Example #20
0
        static public void DrawSymbol(this Graphics self, char c, Font font, RectangleF bounds, StringFormat stringFormat, Brush brush, Brush background)
        {
            var path = new GraphicsPath();

            path.AddString($"{c}", font.FontFamily, 0, font.Size * 0.99f, bounds, stringFormat);
            var iter    = new GraphicsPathIterator(path);
            var subPath = new GraphicsPath();

            while (iter.NextSubpath(subPath, out var _) != 0)
            {
                self.FillRegion(background, new Region(subPath));
            }

            self.FillPath(Brush, path);
            self.DrawString($"{c}", font, brush, bounds, stringFormat);
        }
Example #21
0
        private void GraphicsPathIterator_Paint(object sender,
                                                System.Windows.Forms.PaintEventArgs e)
        {
            // Get the Graphics object
            Graphics g = e.Graphics;
            // Create a Rectangle
            Rectangle rect = new Rectangle(50, 50, 100, 50);
            // Create a Graphics path
            GraphicsPath path = new  GraphicsPath();

            PointF[] ptsArray = { new PointF(20,  20),
                                  new PointF(60,  12),
                                  new PointF(100, 20) };
            // Add a curve, rectangle, ellipse, and a line
            path.AddCurve(ptsArray);
            path.AddRectangle(rect);
            rect.Y += 60;
            path.AddEllipse(rect);
            path.AddLine(120, 50, 220, 100);
            // Draw path
            g.DrawPath(Pens.Blue, path);
            // Create a Graphics path iterator
            GraphicsPathIterator pathIterator =
                new GraphicsPathIterator(path);
            // Display total points and sub paths
            string str = "Total points = "
                         + pathIterator.Count.ToString();

            str += ", Sub paths = "
                   + pathIterator.SubpathCount.ToString();
            MessageBox.Show(str);
            // rewind
            pathIterator.Rewind();
            // Read all subpaths and their properties
            for (int i = 0; i < pathIterator.SubpathCount; i++)
            {
                int  strtIdx, endIdx;
                bool bClosedCurve;
                pathIterator.NextSubpath(out strtIdx,
                                         out endIdx, out bClosedCurve);
                str = "Start Index = " + strtIdx.ToString()
                      + ", End Index = " + endIdx.ToString()
                      + ", IsClosed = " + bClosedCurve.ToString();
                MessageBox.Show(str);
            }
        }
        public void FillPath(Color c, GraphicsPath path)
        {
            GraphicsPathIterator pathIterator = new GraphicsPathIterator(path);


            var polygon = new Polygon();

            for (int i = 0; i < pathIterator.SubpathCount; i++)
            {
                int  strIdx, endIdx;
                bool bClosedCurve;


                pathIterator.NextSubpath(out strIdx, out endIdx, out bClosedCurve);


                List <TriangleNet.Geometry.Vertex> V = new List <TriangleNet.Geometry.Vertex>();
                for (int j = strIdx; j <= endIdx; j++)
                {
                    V.Add(new TriangleNet.Geometry.Vertex(path.PathPoints[j].X, path.PathPoints[j].Y));
                }
                polygon.AddContour(V);
            }



            var options = new ConstraintOptions()
            {
                ConformingDelaunay = true
            };
            var quality = new QualityOptions()
            {
                MinimumAngle = 25
            };

            var mesh = polygon.Triangulate(options, quality);

            foreach (var t in mesh.Triangles)
            {
                var A = t.GetVertex(0);
                var B = t.GetVertex(1);
                var C = t.GetVertex(2);
                AddTriangle((float)A.X, (float)A.Y, (float)B.X, (float)B.Y, (float)C.X, (float)C.Y, c);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.InitialDirectory = Application.StartupPath + datapath.jogpath;
            sfd.Filter           = "Jog paths (*.xml)|*.xml";
            sfd.FileName         = "JogPath.xml";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(sfd.FileName))
                {
                    File.Delete(sfd.FileName);
                }

                XmlWriterSettings set = new XmlWriterSettings();
                set.Indent = true;
                XmlWriter w = XmlWriter.Create(sfd.FileName, set);
                w.WriteStartDocument();
                w.WriteStartElement("view");
                w.WriteAttributeString("raster", nUDRaster.Value.ToString());

                GraphicsPathIterator pathIterator = new GraphicsPathIterator(jogPath);
                pathIterator.Rewind();
                // https://www.c-sharpcorner.com/UploadFile/mahesh/understanding-and-using-graphics-paths-in-gdi/
                for (int i = 0; i < pathIterator.SubpathCount; i++)
                {
                    int  strIdx, endIdx;
                    bool bClosedCurve;
                    pathIterator.NextSubpath(out strIdx, out endIdx, out bClosedCurve);

                    w.WriteStartElement("path");
                    w.WriteAttributeString("id", i.ToString());
                    for (int k = strIdx; k <= endIdx; k++)
                    {
                        w.WriteStartElement("pos");
                        w.WriteAttributeString("X", jogPath.PathPoints[k].X.ToString().Replace(',', '.'));
                        w.WriteAttributeString("Y", jogPath.PathPoints[k].Y.ToString().Replace(',', '.'));
                        w.WriteEndElement();
                    }
                    w.WriteEndElement();
                }
                w.WriteEndElement();
                w.Close();
            }
        }
Example #24
0
        ///<summary>
        /// Extracts the points of the paths in a flat {@link PathIterator} into
        /// a list of Coordinate arrays.
        ///</summary>
        /// <param name="pathIt">A path iterator</param>
        /// <returns>A list of coordinate arrays</returns>
        /// <exception cref="ArgumentException">If a non-linear segment type is encountered</exception>
        public static IList <Coordinate[]> ToCoordinates(GraphicsPathIterator pathIt)
        {
            if (pathIt.HasCurve())
            {
                throw new ArgumentException("Path must not have non-linear segments");
            }

            var  coordArrays = new List <Coordinate[]>();
            int  startIndex, endIndex;
            bool isClosed;

            while (pathIt.NextSubpath(out startIndex, out endIndex, out isClosed) > 0)
            {
                Coordinate[] pts = NextCoordinateArray(pathIt, startIndex, endIndex, isClosed);
                coordArrays.Add(pts);
                if (endIndex == pathIt.Count - 1)
                {
                    break;
                }
            }
            return(coordArrays);
        }
Example #25
0
        public void GeneratePath(ref List pathlist, string str)
        {
            FontFamily   fontFamily = new FontFamily(@"楷体_GB2312");
            int          fontSize   = 512;
            GraphicsPath charPath   = new GraphicsPath();

            charPath.AddString(str, fontFamily, 0, fontSize, new PointF(0, 0), null);
            GraphicsPathIterator iterator;

            iterator = new GraphicsPathIterator(charPath);
            int count = iterator.SubpathCount;

            iterator.Rewind();

            bool iscolse;

            for (int i = 0; i < count; i++)
            {
                GraphicsPath subpath = new GraphicsPath();
                iterator.NextSubpath(subpath, out iscolse);
                pathlist.Add(subpath);
            }
        }
        /// <summary>
        /// returns a newly created graphics path with points distorted
        /// </summary>
        /// <returns>The distorted Graphics Path</returns>
        public GraphicsPath ApplyDistortion()
        {
            var it = new GraphicsPathIterator(_source);

            it.Rewind();
            var Gp         = new GraphicsPath(FillMode.Winding);
            var ReturnPath = new GraphicsPath(FillMode.Winding);

            for (var i = 0; i < it.SubpathCount; i++)
            {
                bool result;
                it.NextSubpath(Gp, out result);

                InjectPrecisionPoints(Gp);

                ReturnPath.AddPolygon(Gp.PathPoints.Select(p => _distortion.Distort(_source, p)).ToArray());
                Gp.Reset();
            }
            it.Dispose();
            Gp.Dispose();

            return(ReturnPath);
        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            Graphic.Init(Graphic.SourceTypes.CSV, "", null, null);
            Graphic.SetHeaderInfo("From Jog path creator");
            Graphic.SetGeometry("Line");

            GraphicsPathIterator pathIterator = new GraphicsPathIterator(jogPath);

            pathIterator.Rewind();
            int pointcnt = 0;

            for (int i = 0; i < pathIterator.SubpathCount; i++)
            {
                int  strIdx, endIdx;
                bool bClosedCurve;
                pathIterator.NextSubpath(out strIdx, out endIdx, out bClosedCurve);

                lastSet = jogPath.PathPoints[endIdx];

                Graphic.SetPathId(i.ToString());
                pointcnt = 0;
                for (int k = strIdx; k <= endIdx; k++)
                {
                    if (pointcnt++ == 0)
                    {
                        Graphic.StartPath(new System.Windows.Point(jogPath.PathPoints[k].X, jogPath.PathPoints[k].Y));
                    }
                    else
                    {
                        Graphic.AddLine(new System.Windows.Point(jogPath.PathPoints[k].X, jogPath.PathPoints[k].Y));
                    }
                }
                Graphic.StopPath();
            }
            Graphic.CreateGCode();
            joggcode = Graphic.GCode.ToString();
        }
Example #28
0
        protected void PerformLayoutBorder(RectangleF innerBorderRect, RenderContext context)
        {
            // Setup border brush
            if (BorderBrush != null && BorderThickness > 0)
            {
                // TODO: Draw border with thickness BorderThickness - doesn't work yet, the drawn line is only one pixel thick
                using (GraphicsPath path = CreateBorderRectPath(innerBorderRect))
                {
                    using (GraphicsPathIterator gpi = new GraphicsPathIterator(path))
                    {
                        PositionColoredTextured[][] subPathVerts = new PositionColoredTextured[gpi.SubpathCount][];
                        using (GraphicsPath subPath = new GraphicsPath())
                        {
                            for (int i = 0; i < subPathVerts.Length; i++)
                            {
                                bool isClosed;
                                gpi.NextSubpath(subPath, out isClosed);
                                PointF[]    pathPoints = subPath.PathPoints;
                                PenLineJoin lineJoin   = Math.Abs(CornerRadius) < DELTA_DOUBLE ? BorderLineJoin : PenLineJoin.Bevel;
                                TriangulateHelper.TriangulateStroke_TriangleList(pathPoints, (float)BorderThickness, isClosed, 1, lineJoin,
                                                                                 out subPathVerts[i]);
                            }
                        }
                        PositionColoredTextured[] verts;
                        GraphicsPathHelper.Flatten(subPathVerts, out verts);
                        BorderBrush.SetupBrush(this, ref verts, context.ZOrder, true);

                        PrimitiveBuffer.SetPrimitiveBuffer(ref _borderContext, ref verts, PrimitiveType.TriangleList);
                    }
                }
            }
            else
            {
                PrimitiveBuffer.DisposePrimitiveBuffer(ref _borderContext);
            }
        }
Example #29
0
        public void PreCalc32Strokes()
        {
            if (m_32BasicStrokenBounds.Count > 0)
            {
                return;
            }

            //
            FontFamily fontFamily = new FontFamily(@"楷体_GB2312");
            int        fontSize   = 512;
            bool       iscolse    = false;

            for (int i = 0; i < MAX_BASIC_STROKE; i++)
            {
                GraphicsPath charPath = new GraphicsPath();
                charPath.AddString(StrokeInChinese[i], fontFamily, 0, fontSize, new PointF(0, 0), null);
                GraphicsPathIterator iterator;
                iterator = new GraphicsPathIterator(charPath);
                int count = iterator.SubpathCount;
                iterator.Rewind();

                GraphicsPath bihua = new GraphicsPath();
                for (int j = 0; j < count; j++)
                {
                    GraphicsPath subpath = new GraphicsPath();
                    iterator.NextSubpath(subpath, out iscolse);

                    if (StrokeIndexInKaitiGB2312_a[i] == j || StrokeIndexInKaitiGB2312_b[i] == j)
                    {
                        bihua.AddPath(subpath, false);
                    }
                    if (j == StrokeIndexInKaitiGB2312_b[i])
                    {
                        break;
                    }
                }
                //Compute Bounds of Path
                RectangleF b;
                b = bihua.GetBounds();

                //Transform to 64x64
                Matrix translateMatrix = new Matrix();
                float  scale           = 64.0f / Math.Max(b.Width, b.Height);
                //Translate by Top Left
                translateMatrix.Translate(-b.X * scale, -b.Y * scale);
                //Scale by MAX (W/h)
                translateMatrix.Scale(scale, scale);
                bihua.Transform(translateMatrix);

                b = bihua.GetBounds();

                //Create Region
                Region r = new Region(bihua);
                //translateMatrix.Reset();
                //RegionData myRegionData = r.GetRegionData();

                int area = 0;
                for (int x = 0; x < 64; x++)
                {
                    for (int y = 0; y < 64; y++)
                    {
                        if (r.IsVisible(x, y))
                        {
                            area++;
                        }
                    }
                }
                m_32BasicStrokes.Add(bihua);
                m_32BasicStrokenBounds.Add(b);
                m_32BasicStroken_Area.Add(area);

                iterator.Dispose();
                charPath.Dispose();
            }
        }
Example #30
0
    public GraphicsPath RandomWarp(GraphicsPath path)
    {
        // Add line //
        int PsCount = 10;
        PointF[] curvePs = new PointF[PsCount * 2];
        for (int u = 0; u < PsCount; u++)
        {
            curvePs[u].X = u * (Width / PsCount);
            curvePs[u].Y = Height / 2;
        }
        for (int u = PsCount; u < (PsCount * 2); u++)
        {
            curvePs[u].X = (u - PsCount) * (Width / PsCount);
            curvePs[u].Y = Height / 2 + 2;
        }

        double eps = Height * 0.05;

        double amp = rnd.NextDouble() * (double)(Height / 3);
        double size = rnd.NextDouble() * (double)(Width / 4) + Width / 8;

        double offset = (double)(Height / 3);

        PointF[] pn = new PointF[path.PointCount];
        byte[] pt = new byte[path.PointCount];

        GraphicsPath np2 = new GraphicsPath();

        GraphicsPathIterator iter = new GraphicsPathIterator(path);
        for (int i = 0; i < iter.SubpathCount; i++)
        {
            GraphicsPath sp = new GraphicsPath();
            bool closed;
            iter.NextSubpath(sp, out closed);

            Matrix m = new Matrix();
            m.RotateAt(Convert.ToSingle(rnd.NextDouble() * 30 - 15), sp.PathPoints[0]);

            m.Translate(-1 * i, 0);//uncomment

            sp.Transform(m);

            np2.AddPath(sp, true);
        }

        for (int i = 0; i < np2.PointCount; i++)
        {
            //pn[i] = Noise( path.PathPoints[i] , eps);
            pn[i] = Wave(np2.PathPoints[i], amp, size);
            pt[i] = np2.PathTypes[i];
        }

        GraphicsPath newpath = new GraphicsPath(pn, pt);

        return newpath;
    }
Example #31
0
    public GraphicsPath RandomWarp(GraphicsPath path)
    {
        // Add line //
        int PsCount = 10;

        PointF[] curvePs = new PointF[PsCount * 2];
        for (int u = 0; u < PsCount; u++)
        {
            curvePs[u].X = u * (Width / PsCount);
            curvePs[u].Y = Height / 2;
        }
        for (int u = PsCount; u < (PsCount * 2); u++)
        {
            curvePs[u].X = (u - PsCount) * (Width / PsCount);
            curvePs[u].Y = Height / 2 + 2;
        }


        double eps = Height * 0.05;

        double amp  = rnd.NextDouble() * (double)(Height / 3);
        double size = rnd.NextDouble() * (double)(Width / 4) + Width / 8;

        double offset = (double)(Height / 3);


        PointF[] pn = new PointF[path.PointCount];
        byte[]   pt = new byte[path.PointCount];

        GraphicsPath np2 = new GraphicsPath();

        GraphicsPathIterator iter = new GraphicsPathIterator(path);

        for (int i = 0; i < iter.SubpathCount; i++)
        {
            GraphicsPath sp = new GraphicsPath();
            bool         closed;
            iter.NextSubpath(sp, out closed);

            Matrix m = new Matrix();
            m.RotateAt(Convert.ToSingle(rnd.NextDouble() * 30 - 15), sp.PathPoints[0]);

            m.Translate(-1 * i, 0);//uncomment

            sp.Transform(m);

            np2.AddPath(sp, true);
        }



        for (int i = 0; i < np2.PointCount; i++)
        {
            //pn[i] = Noise( path.PathPoints[i] , eps);
            pn[i] = Wave(np2.PathPoints[i], amp, size);
            pt[i] = np2.PathTypes[i];
        }

        GraphicsPath newpath = new GraphicsPath(pn, pt);

        return(newpath);
    }