forward path writer
예제 #1
0
 //-------------------------------------------------
 public static void WriteToStream(BinaryWriter writer, PathWriter pathSource)
 {
     int num_vertice;
     int num_alloc_vertice;
     double[] coord_xy;
     byte[] cmds;
     PathWriter.UnsafeDirectGetData(pathSource,
         out num_alloc_vertice,
         out num_vertice,
         out coord_xy,
         out cmds);
     //write to binary format ?
     //1.  
     writer.Write(num_alloc_vertice);//hint
     //2. 
     writer.Write(num_vertice); //actual vertices
     //3. all vertice
     int totalCoord = num_vertice << 1;
     for (int i = 0; i < totalCoord; )
     {
         writer.Write(coord_xy[i]);//x
         i++;
         writer.Write(coord_xy[i]);//y
         i++;
     }
     writer.Write(num_vertice); //actual vertices
     //4. all commands
     for (int i = 0; i < num_vertice; ++i)
     {
         writer.Write((byte)cmds[i]);
     }
     writer.Write((int)0);
     writer.Flush();
     //------------------------------------
 }
예제 #2
0
 public static void UnsafeDirectSetData(SpriteShape lion,
     int numPaths,
     PathWriter pathStore,
     Color[] colors,
     int[] pathIndice)
 {
     lion.path = pathStore;
     lion.colors = colors;
     lion.pathIndexList = pathIndice;
     lion.numPaths = numPaths;
     lion.UpdateBoundingRect();
 }
예제 #3
0
        public VertexStore MakeVxs()
        {
            PathWriter m_LinesToDraw = new PathWriter();

            m_LinesToDraw.Clear();
            m_LinesToDraw.MoveTo(bounds.Left, bounds.Bottom);
            m_LinesToDraw.LineTo(bounds.Right, bounds.Bottom);
            m_LinesToDraw.LineTo(bounds.Right, bounds.Top);
            m_LinesToDraw.LineTo(bounds.Left, bounds.Top);
            m_LinesToDraw.CloseFigure();
            return(m_LinesToDraw.Vxs);
        }
예제 #4
0
 public static void UnsafeDirectGetData(
     PathWriter pathStore,
     out int m_allocated_vertices,
     out int m_num_vertices,
     out double[] m_coord_xy,
     out byte[] m_CommandAndFlags)
 {
     VertexStore.UnsafeDirectGetData(
         pathStore.Vxs,
         out m_allocated_vertices,
         out m_num_vertices,
         out m_coord_xy,
         out m_CommandAndFlags);
 }
예제 #5
0
 public static void UnsafeDirectSetData(
     PathWriter pathStore,
     int m_allocated_vertices,
     int m_num_vertices,
     double[] m_coord_xy,
     VertexCmd[] m_CommandAndFlags)
 {
     VertexStore.UnsafeDirectSetData(
         pathStore.Vxs,
         m_allocated_vertices,
         m_num_vertices,
         m_coord_xy,
         m_CommandAndFlags);
 }
예제 #6
0
 public static void Load(PathWriter vertexSource, string pathAndFileName)
 {
     //vertexSource.Clear();
     //var vxs = vertexSource.Vxs;
     //string[] allLines = File.ReadAllLines(pathAndFileName);
     //foreach (string line in allLines)
     //{
     //    string[] elements = line.Split(',');
     //    double x = double.Parse(elements[0]);
     //    double y = double.Parse(elements[1]);
     //    VertexCmd flagsAndCommand = (VertexCmd)System.Enum.Parse(typeof(VertexCmd), elements[2].Trim());
     //    int len = elements.Length;
     //    for (int i = 3; i < len; i++)
     //    {
     //        flagsAndCommand |= (VertexCmd)System.Enum.Parse(typeof(VertexCmd), elements[i].Trim());
     //    }
     //    vxs.AddVertex(x, y, flagsAndCommand);
     //}
 }
예제 #7
0
 public static void Load(PathWriter vertexSource, string pathAndFileName)
 {
     //vertexSource.Clear();
     //var vxs = vertexSource.Vxs;
     //string[] allLines = File.ReadAllLines(pathAndFileName);
     //foreach (string line in allLines)
     //{
     //    string[] elements = line.Split(',');
     //    double x = double.Parse(elements[0]);
     //    double y = double.Parse(elements[1]);
     //    VertexCmd flagsAndCommand = (VertexCmd)System.Enum.Parse(typeof(VertexCmd), elements[2].Trim());
     //    int len = elements.Length;
     //    for (int i = 3; i < len; i++)
     //    {
     //        flagsAndCommand |= (VertexCmd)System.Enum.Parse(typeof(VertexCmd), elements[i].Trim());
     //    }
     //    vxs.AddVertex(x, y, flagsAndCommand);
     //}
 }
예제 #8
0
        //public static void Save(IVertexSource vertexSource, string pathAndFileName, bool oldStyle = true)
        //{
        //    if (oldStyle)
        //    {
        //        using (StreamWriter outFile = new StreamWriter(pathAndFileName))
        //        {
        //            vertexSource.RewindZero();
        //            double x;
        //            double y;
        //            ShapePath.FlagsAndCommand flagsAndCommand = vertexSource.GetNextVertex(out x, out y);
        //            do
        //            {
        //                outFile.WriteLine("{0}, {1}, {2}", x, y, flagsAndCommand.ToString());
        //                flagsAndCommand = vertexSource.GetNextVertex(out x, out y);
        //            }
        //            while (flagsAndCommand != ShapePath.FlagsAndCommand.CommandStop);
        //        }
        //    }
        //    else
        //    {
        //        using (StreamWriter outFile = new StreamWriter(pathAndFileName))
        //        {
        //            foreach (VertexData vertexData in vertexSource.GetVertexIter())
        //            {
        //                outFile.WriteLine("{0}, {1}, {2}", vertexData.position.x, vertexData.position.y, vertexData.command.ToString());
        //            }
        //        }
        //    }
        //}


        //-------------------------------------------------
        public static void WriteToStream(BinaryWriter writer, PathWriter pathSource)
        {
            int num_vertice;
            int num_alloc_vertice;

            double[]    coord_xy;
            VertexCmd[] cmds;
            PathWriter.UnsafeDirectGetData(pathSource,
                                           out num_alloc_vertice,
                                           out num_vertice,
                                           out coord_xy,
                                           out cmds);

            //write to binary format ?
            //1.
            writer.Write(num_alloc_vertice); //hint
            //2.
            writer.Write(num_vertice);       //actual vertices
            //3. all vertice
            int totalCoord = num_vertice << 1;

            for (int i = 0; i < totalCoord;)
            {
                writer.Write(coord_xy[i]); //x
                i++;
                writer.Write(coord_xy[i]); //y
                i++;
            }
            writer.Write(num_vertice); //actual vertices
            //4. all commands
            for (int i = 0; i < num_vertice; ++i)
            {
                writer.Write((byte)cmds[i]);
            }
            writer.Write((int)0);
            writer.Flush();
            //------------------------------------
        }
예제 #9
0
        public static void ReadPathDataFromStream(BinaryReader reader, out PathWriter newPath)
        {
            newPath = new PathWriter();
            //1.
            int num_alloc_vertice = reader.ReadInt32(); //hint
            //2.
            int num_vertice = reader.ReadInt32();       //actual vertice num
            int totalCoord  = num_vertice << 1;

            //3.
            double[] coord_xy = new double[totalCoord];
            //4.
            VertexCmd[] cmds = new VertexCmd[num_vertice];

            for (int i = 0; i < totalCoord;)
            {
                coord_xy[i] = reader.ReadDouble();
                i++;
                coord_xy[i] = reader.ReadDouble();
                i++;
            }
            //4.
            int cmds_count = reader.ReadInt32();

            for (int i = 0; i < cmds_count; ++i)
            {
                cmds[i] = (VertexCmd)reader.ReadByte();
            }

            PathWriter.UnsafeDirectSetData(
                newPath,
                num_alloc_vertice,
                num_vertice,
                coord_xy,
                cmds);
            int end = reader.ReadInt32();
        }
예제 #10
0
 public static void UnsafeDirectGetData(
     PathWriter pathStore,
     out int m_allocated_vertices,
     out int m_num_vertices,
     out double[] m_coord_xy,
     out byte[] m_CommandAndFlags)
 {
     VertexStore.UnsafeDirectGetData(
         pathStore.Vxs,
         out m_allocated_vertices,
         out m_num_vertices,
         out m_coord_xy,
         out m_CommandAndFlags);
 }
예제 #11
0
        public static void ReadPathDataFromStream(BinaryReader reader, out PathWriter newPath)
        {
            newPath = new PathWriter();
            //1.
            int num_alloc_vertice = reader.ReadInt32();//hint
            //2.
            int num_vertice = reader.ReadInt32();//actual vertice num
            int totalCoord = num_vertice << 1;
            //3.
            double[] coord_xy = new double[totalCoord];
            //4.
            byte[] cmds = new byte[num_vertice];
            for (int i = 0; i < totalCoord; )
            {
                coord_xy[i] = reader.ReadDouble();
                i++;
                coord_xy[i] = reader.ReadDouble();
                i++;
            }
            //4.
            int cmds_count = reader.ReadInt32();
            for (int i = 0; i < cmds_count; ++i)
            {
                cmds[i] = reader.ReadByte();
            }

            PathWriter.UnsafeDirectSetData(
                newPath,
                num_alloc_vertice,
                num_vertice,
                coord_xy,
                cmds);
            int end = reader.ReadInt32();
        }
예제 #12
0
        static public int LoadLionData(PathWriter path, PixelFarm.Drawing.Color[] colors, int[] path_idx)
        {
            // Parse the lion and then detect its bounding
            // box and arrange polygons orientations (make all polygons
            // oriented clockwise or counterclockwise)

            int npaths = 0;
            string[] splitOnNL = g_lion.Split('\n');
            foreach (string line in splitOnNL)
            {
                int newColor;
                if (line.Length > 0
                    && line[0] != 'M'
                    && Int32.TryParse(line, NumberStyles.HexNumber, null, out newColor))
                {
                    // New color. Every new color creates new path in the path object.
                    path.CloseFigure();
                    colors[npaths] = PixelFarm.Drawing.Color.CreatRGB8Packed((int)newColor);
                    path_idx[npaths] = path.StartFigure();
                    npaths++;
                }
                else
                {
                    bool startedPoly = false;
                    string[] splitOnSpace = line.Split(' ');
                    for (int i = 0; i < splitOnSpace.Length; i++)
                    {
                        string[] splitOnComma = splitOnSpace[i].Split(',');
                        if (splitOnComma.Length > 1)
                        {
                            double x = 0.0;
                            double y = 0.0;
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);
                            if (!startedPoly)
                            {
                                startedPoly = true;
                                path.CloseFigure();
                                path.MoveTo(x, y);
                            }
                            else
                            {
                                path.LineTo(x, y);
                            }
                        }
                    }
                }
            }

            //path.ArrangeOrientationsAll(ShapePath.FlagsAndCommand.FlagCW);

            VertexHelper.ArrangeOrientationsAll(path.Vxs, true);
            return npaths;
        }
예제 #13
0
        public static List <VertexStore> CombinePaths(VertexStoreSnap a, VertexStoreSnap b, VxsClipperType vxsClipType, bool separateIntoSmallSubPaths)
        {
            //TODO: optimize here

            ClipType clipType = (ClipType)vxsClipType;
            List <List <IntPoint> > aPolys = CreatePolygons(a);
            List <List <IntPoint> > bPolys = CreatePolygons(b);
            Clipper clipper = new Clipper();

            clipper.AddPaths(aPolys, PolyType.ptSubject, true);
            clipper.AddPaths(bPolys, PolyType.ptClip, true);
            List <List <IntPoint> > intersectedPolys = new List <List <IntPoint> >();

            clipper.Execute(clipType, intersectedPolys);
            List <VertexStore> resultList = new List <VertexStore>();

            PathWriter outputPathWriter = new PathWriter();

            if (separateIntoSmallSubPaths)
            {
                foreach (List <IntPoint> polygon in intersectedPolys)
                {
                    int j = polygon.Count;
                    if (j > 0)
                    {
                        //first one
                        IntPoint point = polygon[0];
                        outputPathWriter.MoveTo(point.X / 1000.0, point.Y / 1000.0);
                        //next others ...
                        if (j > 1)
                        {
                            for (int i = 1; i < j; ++i)
                            {
                                point = polygon[i];
                                outputPathWriter.LineTo(point.X / 1000.0, point.Y / 1000.0);
                            }
                        }

                        outputPathWriter.CloseFigure();
                        resultList.Add(outputPathWriter.Vxs);
                        //---
                        //clear
                        outputPathWriter.ClearAndStartNewVxs(new VertexStore());
                    }
                }
            }
            else
            {
                foreach (List <IntPoint> polygon in intersectedPolys)
                {
                    int j = polygon.Count;
                    if (j > 0)
                    {
                        //first one
                        IntPoint point = polygon[0];
                        outputPathWriter.MoveTo(point.X / 1000.0, point.Y / 1000.0);
                        //next others ...
                        if (j > 1)
                        {
                            for (int i = 1; i < j; ++i)
                            {
                                point = polygon[i];
                                outputPathWriter.LineTo(point.X / 1000.0, point.Y / 1000.0);
                            }
                        }
                        outputPathWriter.CloseFigure();
                    }
                }

                //TODO: review here
                outputPathWriter.Stop();
                resultList.Add(outputPathWriter.Vxs);
            }

            return(resultList);
        }
예제 #14
0
        public static List <VertexStore> CombinePaths(VertexStoreSnap a, VertexStoreSnap b, VxsClipperType vxsClipType, bool separateIntoSmallSubPaths)
        {
            ClipType clipType = (ClipType)vxsClipType;
            List <List <IntPoint> > aPolys = CreatePolygons(a);
            List <List <IntPoint> > bPolys = CreatePolygons(b);
            Clipper clipper = new Clipper();

            clipper.AddPaths(aPolys, PolyType.ptSubject, true);
            clipper.AddPaths(bPolys, PolyType.ptClip, true);
            List <List <IntPoint> > intersectedPolys = new List <List <IntPoint> >();

            clipper.Execute(clipType, intersectedPolys);
            List <VertexStore> resultList = new List <VertexStore>();
            PathWriter         output     = new PathWriter();

            if (separateIntoSmallSubPaths)
            {
                foreach (List <IntPoint> polygon in intersectedPolys)
                {
                    int j = polygon.Count;
                    if (j > 0)
                    {
                        //first one
                        IntPoint point = polygon[0];
                        output.MoveTo(point.X / 1000.0, point.Y / 1000.0);
                        //next others ...
                        if (j > 1)
                        {
                            for (int i = 1; i < j; ++i)
                            {
                                point = polygon[i];
                                output.LineTo(point.X / 1000.0, point.Y / 1000.0);
                            }
                        }

                        output.CloseFigure();
                        resultList.Add(output.Vxs);
                        //---
                        //clear
                        output.ClearAndStartNewVxs();
                    }
                }
            }
            else
            {
                foreach (List <IntPoint> polygon in intersectedPolys)
                {
                    int j = polygon.Count;
                    if (j > 0)
                    {
                        //first one
                        IntPoint point = polygon[0];
                        output.MoveTo(point.X / 1000.0, point.Y / 1000.0);
                        //next others ...
                        if (j > 1)
                        {
                            for (int i = 1; i < j; ++i)
                            {
                                point = polygon[i];
                                output.LineTo(point.X / 1000.0, point.Y / 1000.0);
                            }
                        }
                        output.CloseFigure();
                    }

                    //bool first = true;
                    //foreach (IntPoint point in polygon)
                    //{
                    //    if (first)
                    //    {
                    //        output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandMoveTo);
                    //        first = false;
                    //    }
                    //    else
                    //    {
                    //        output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandLineTo);
                    //    }
                    //}
                }

                output.Stop();
                resultList.Add(output.Vxs);
            }

            return(resultList);
        }
예제 #15
0
        public static List<VertexStore> CombinePaths(VertexStoreSnap a, VertexStoreSnap b, VxsClipperType vxsClipType, bool separateIntoSmallSubPaths)
        {
            ClipType clipType = (ClipType)vxsClipType;
            List<List<IntPoint>> aPolys = CreatePolygons(a);
            List<List<IntPoint>> bPolys = CreatePolygons(b);
            Clipper clipper = new Clipper();
            clipper.AddPaths(aPolys, PolyType.ptSubject, true);
            clipper.AddPaths(bPolys, PolyType.ptClip, true);
            List<List<IntPoint>> intersectedPolys = new List<List<IntPoint>>();
            clipper.Execute(clipType, intersectedPolys);
            List<VertexStore> resultList = new List<VertexStore>();

            PathWriter output = new PathWriter();
            if (separateIntoSmallSubPaths)
            {
                foreach (List<IntPoint> polygon in intersectedPolys)
                {
                    int j = polygon.Count;
                    if (j > 0)
                    {
                        //first one
                        IntPoint point = polygon[0];
                        output.MoveTo(point.X / 1000.0, point.Y / 1000.0);
                        //next others ...
                        if (j > 1)
                        {
                            for (int i = 1; i < j; ++i)
                            {
                                point = polygon[i];
                                output.LineTo(point.X / 1000.0, point.Y / 1000.0);
                            }
                        }

                        output.CloseFigure();
                        resultList.Add(output.Vxs);
                        //---
                        //clear 
                        output.ClearAndStartNewVxs(new VertexStore());
                    }
                }
            }
            else
            {
                foreach (List<IntPoint> polygon in intersectedPolys)
                {
                    int j = polygon.Count;
                    if (j > 0)
                    {
                        //first one
                        IntPoint point = polygon[0];
                        output.MoveTo(point.X / 1000.0, point.Y / 1000.0);
                        //next others ...
                        if (j > 1)
                        {
                            for (int i = 1; i < j; ++i)
                            {
                                point = polygon[i];
                                output.LineTo(point.X / 1000.0, point.Y / 1000.0);
                            }
                        }
                        output.CloseFigure();
                    }

                    //bool first = true;
                    //foreach (IntPoint point in polygon)
                    //{
                    //    if (first)
                    //    {
                    //        output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandMoveTo);
                    //        first = false;
                    //    }
                    //    else
                    //    {
                    //        output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandLineTo);
                    //    }
                    //} 
                }

                output.Stop();
                resultList.Add(output.Vxs);
            }

            return resultList;
        }