Example #1
0
        Stream GetCSewFigSeg(List <List <Coords> > blocks)
        {
            Stream stream = new MemoryStream();


            stitchBlock currentBlock;
            int         StitchesCount = blocks.Sum(block => block.Count);

            currentBlock = new stitchBlock();
            stream.Write(GetCSegSewName(), 0, 7);
            //  write prefix
            //  (color start indicator) (all color changes have the same value for this field;
            //  if the value here is not the same as the first block, it's not a color change)
            //(color index)
            //(number of stitches in this block)
            stream.Write(GetColorInfo(), 0, 4);

            stream.WriteAsUInt16(StitchesCount);

            foreach (Coords stitchPoint in blocks.SelectMany(stitch => stitch))
            {
                stream.WritePesCoords(ShiftCoords(stitchPoint, _designXOffset, _designYOffset));
            }

            stream.Write(GetColorTable(), 0, 10);
            return(stream);
        }
Example #2
0
        List <stitchBlock> filterStitches(List <stitchBlock> input, int threshold)
        {
            List <stitchBlock> retval         = new List <stitchBlock>();
            List <Point>       tempStitchData = new List <Point>();

            for (int x = 0; x < input.Count; x++)
            {
                for (int i = 0; i < input[x].stitches.Length; i++)
                {
                    if (i > 0)//need a previous point to check against, can't check the first
                    {
                        double diffx = Math.Abs(input[x].stitches[i].X - input[x].stitches[i - 1].X);
                        double diffy = Math.Abs(input[x].stitches[i].Y - input[x].stitches[i - 1].Y);
                        if (Math.Sqrt(Math.Pow(diffx, 2.0) + Math.Pow(diffy, 2.0)) < threshold) //check distance between this point and the last one
                        {
                            if (tempStitchData.Count == 0 && i > 1)                             //first stitch of block gets left out without this, except for very first stitch
                            {
                                tempStitchData.Add(input[x].stitches[i - 1]);
                            }
                            tempStitchData.Add(input[x].stitches[i]);
                        }
                        else//stitch is too far from the previous one
                        {
                            if (tempStitchData.Count > 2)//add the block and start a new one
                            {
                                stitchBlock tempBlock = new stitchBlock();
                                tempBlock.color      = input[x].color;
                                tempBlock.colorIndex = input[x].colorIndex;
                                tempBlock.stitches   = new Point[tempStitchData.Count];
                                tempStitchData.CopyTo(tempBlock.stitches);
                                retval.Add(tempBlock);
                                tempStitchData = new List <Point>();
                            }
                            else//reset variables
                            {
                                tempStitchData = new List <Point>();
                            }
                        }
                    }
                    else //just add the first one, don't have anything to compare against
                    {
                        tempStitchData.Add(input[x].stitches[i]);
                    }
                }
                if (tempStitchData.Count > 2)
                {
                    stitchBlock tempBlock = new stitchBlock();
                    tempBlock.color      = input[x].color;
                    tempBlock.colorIndex = input[x].colorIndex;
                    tempBlock.stitches   = new Point[tempStitchData.Count];
                    tempStitchData.CopyTo(tempBlock.stitches);
                    retval.Add(tempBlock);
                    tempStitchData = new List <Point>();
                }
            }
            return(retval);
        }