コード例 #1
0
        public List <RegMesh2D> Generate(IContour contour)
        {
            IPoint[,] points = new Point[this.nY, this.nX];
            ICurve a1 = contour[0];
            ICurve a2 = contour[1];
            ICurve a3 = contour[2];
            ICurve a4 = contour[3];

            for (int i = 0; i < this.nY; i++)
            {
                double xA, yA, xB, yB;
                a4.getPoint(1 - i * hY, out xA, out yA);
                a2.getPoint(i * hY, out xB, out yB);
                ICurve curve = new Relocate(new Morph(a1, a3, i * hY), new Point(xA, yA), new Point(xB, yB));
                for (int j = 0; j < this.nX; j++)
                {
                    double x, y;
                    curve.getPoint(j * hX, out x, out y);
                    points[i, j] = new Point(x, y);
                }
            }
            return(new List <RegMesh2D>()
            {
                new RegMesh2D(points, nX, nY)
            });
        }
コード例 #2
0
ファイル: Figures.cs プロジェクト: zwcloud/Typography
        static Poly2Tri.Polygon CreatePolygon(IContour cnt)
        {
            using (Borrow(out List <Poly2Tri.TriangulationPoint> points))
            {
                //limitation: poly tri not accept duplicated points! ***
                double prevX = 0;
                double prevY = 0;
                int    j     = cnt.VertexCount;

                for (int i = 0; i < j; ++i)
                {
                    cnt.GetVertex(i, out float x, out float y, out object userData);
                    if (x == prevX && y == prevY)
                    {
                        if (i > 0)
                        {
                            //skip duplicated point, not use
                            continue;
                        }
                    }
                    else
                    {
                        //var triPoint = new Poly2Tri.TriangulationPoint(prevX = x, prevY = y) { userData = p };
                        //points.Add(triPoint);
                        points.Add(new Poly2Tri.TriangulationPoint(prevX = x, prevY = y, userData));
                    }
                }
                return(new Poly2Tri.Polygon(points.ToArray()));
            }
        }
コード例 #3
0
        /**
         *   @brief Retrieve an IContour object using index (that relates to the given order).
         *   @param[in] index - the zero-based index of the requested contour (between 0 and QueryNumberOfContours()-1 ).
         *   @param[out] contourData - contains the extracted contour line data.
         *
         *   @return PXCM_STATUS_NO_ERROR - successful operation.
         *   @return PXCM_STATUS_DATA_UNAVAILABLE  - index >= number of detected contours.
         *
         *   @see IContour
         */
        public pxcmStatus QueryContour(Int32 index, out IContour contourData)
        {
            IntPtr     cd2;
            pxcmStatus sts = PXCMBlobData_IBlob_QueryContour(instance, index, out cd2);

            contourData = (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) ? new IContour(cd2) : null;
            return(sts);
        }
コード例 #4
0
 public List <RegMesh2D> Generate(IContour contour)
 {
     this.mesh    = new List <RegMesh2D>();
     contourArray = decompos.decomposed(contour);
     for (int i = 0; i < 3; i++)
     {
         mesh.Add(meshgen.Generate(contourArray[i])[0]);
     }
     return(mesh);
 }
コード例 #5
0
        // находит цетр для треугольника
        /// <summary>
        /// chahged method for find center of pentagon
        /// </summary>
        /// <param name="contour"></param>
        /// <returns> contour</returns>
        private IPoint findCenterPentagon(IContour contour)
        {
            pointsOfCurvs = new List <IPoint>();
            IPoint[] points = new IPoint[3];
            for (int i = 0; i < 5; ++i)
            {
                contour[i].accept(this);
            }

            return(new Geometry.Point((pointsOfCurvs[0].X + pointsOfCurvs[1].X + pointsOfCurvs[2].X + pointsOfCurvs[3].X + pointsOfCurvs[4].X) / 5, (pointsOfCurvs[0].Y + pointsOfCurvs[1].Y + pointsOfCurvs[2].Y + pointsOfCurvs[3].Y + pointsOfCurvs[4].Y) / 5));
        }
コード例 #6
0
        public List <RegMesh2D> Generate(IContour contour)
        {
            this.mesh    = new List <RegMesh2D>();
            this.contour = contour;
            numOfCurvs   = contour.Size;
            switch (numOfCurvs)
            {
            case 4:
                lenghtOfPart = getSizeOfPart(Tools.length(contour[0]));
                createVectorOfParam();
                mesh.Add(new RegMesh2D(nY, nX));
                fillMesh();
                return(mesh);

            default:
                return(null);
            }
        }
コード例 #7
0
        public IContour[] decomposed(IContour contour)
        {
            triangles = new List <IContour>();

            pointOfMiddle = findCenterPentagon(contour);
            // create five triangles for pentagon
            triangles.Add(new Contour(new List <ICurve> {
                contour[0], new Line(pointsOfCurvs[1], pointOfMiddle), new Line(pointOfMiddle, pointsOfCurvs[0])
            }));
            triangles.Add(new Contour(new List <ICurve> {
                contour[1], new Line(pointsOfCurvs[2], pointOfMiddle), new Line(pointOfMiddle, pointsOfCurvs[1])
            }));
            triangles.Add(new Contour(new List <ICurve> {
                contour[2], new Line(pointsOfCurvs[3], pointOfMiddle), new Line(pointOfMiddle, pointsOfCurvs[2])
            }));
            triangles.Add(new Contour(new List <ICurve> {
                contour[3], new Line(pointsOfCurvs[4], pointOfMiddle), new Line(pointOfMiddle, pointsOfCurvs[3])
            }));
            triangles.Add(new Contour(new List <ICurve> {
                contour[4], new Line(pointsOfCurvs[0], pointOfMiddle), new Line(pointOfMiddle, pointsOfCurvs[4])
            }));
            return(triangles.ToArray());
        }
コード例 #8
0
        public IContour[] decomposed(IContour contour)
        {
            pointsOfCurvs  = new List <IPoint>();
            generalPoints  = new List <IPoint>();
            preDecompose   = new List <ICurve>();
            finalDecompose = new List <IContour>();
            for (int i = 0; i < 5; i++)     //вызываем кривые, чтобы они вызвали метод visitLine и отдали нам свои точки в pointsOfCurvs
            {
                contour[i].accept(this);
            }
            preDecompose.Add((new Line(pointsOfCurvs[0], pointsOfCurvs[2])));       //0
            preDecompose.Add((new Line(pointsOfCurvs[0], pointsOfCurvs[3])));       //1
            preDecompose.Add((new Line(pointsOfCurvs[1], pointsOfCurvs[3])));       //2
            preDecompose.Add((new Line(pointsOfCurvs[1], pointsOfCurvs[4])));       //3
            preDecompose.Add((new Line(pointsOfCurvs[2], pointsOfCurvs[4])));       //4

            generalPoints.Add(findGeneralPoints(preDecompose[0], preDecompose[3])); //1
            generalPoints.Add(findGeneralPoints(preDecompose[0], preDecompose[2])); //2
            generalPoints.Add(findGeneralPoints(preDecompose[4], preDecompose[2])); //3
            generalPoints.Add(findGeneralPoints(preDecompose[1], preDecompose[4])); //4
            generalPoints.Add(findGeneralPoints(preDecompose[3], preDecompose[1])); //5

            finalDecompose.Add(new Contour(new List <ICurve> {
                contour[0], new Line(pointsOfCurvs[1], generalPoints[4]), new Line(generalPoints[4], pointsOfCurvs[0])
            }));
            finalDecompose.Add(new Contour(new List <ICurve> {
                contour[1], new Line(pointsOfCurvs[2], generalPoints[0]), new Line(generalPoints[0], pointsOfCurvs[1])
            }));
            finalDecompose.Add(new Contour(new List <ICurve> {
                contour[3], contour[4], new Line(pointsOfCurvs[0], pointsOfCurvs[3])
            }));
            finalDecompose.Add(new Contour(new List <ICurve> {
                new Line(generalPoints[0], pointsOfCurvs[2]), contour[2], new Line(pointsOfCurvs[3], generalPoints[4]), new Line(generalPoints[4], generalPoints[0])
            }));

            return(finalDecompose.ToArray());
        }
コード例 #9
0
        /* Displaying Depth/Mask Images - for depth image only we use a delay of NumberOfFramesToDelay to sync image with tracking */
        private unsafe void DisplayPicture(Image depth, HandData handAnalysis)
        {
            if (depth == null)
            {
                return;
            }

            Image image = depth;


            //Mask Image
            if (_form.GetLabelmapState())
            {
                System.Drawing.Bitmap labeledBitmap = null;
                try
                {
                    int numOfHands = handAnalysis.NumberOfHands;

                    PointI32[][] pointOuter = new PointI32[numOfHands][];
                    PointI32[][] pointInner = new PointI32[numOfHands][];

                    labeledBitmap = new System.Drawing.Bitmap(image.Info.width, image.Info.height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    for (int j = 0; j < numOfHands; j++)
                    {
                        int       id;
                        ImageData data;

                        handAnalysis.QueryHandId(AccessOrderType.ACCESS_ORDER_BY_TIME, j, out id);
                        //Get hand by time of appearance
                        IHand handData;
                        handAnalysis.QueryHandData(AccessOrderType.ACCESS_ORDER_BY_TIME, j, out handData);
                        if (handData != null)
                        {
                            image = handData.SegmentationImage;
                            if (image != null)
                            {
                                if (image.AcquireAccess(ImageAccess.ACCESS_READ, PixelFormat.PIXEL_FORMAT_Y8,
                                                        out data) >= Status.STATUS_NO_ERROR)
                                {
                                    var rect = new System.Drawing.Rectangle(0, 0, image.Info.width, image.Info.height);

                                    var   bitmapdata = labeledBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, labeledBitmap.PixelFormat);
                                    byte *numPtr     = (byte *)bitmapdata.Scan0; //dst
                                    byte *numPtr2    = (byte *)data.planes[0];   //row
                                    int   imagesize  = image.Info.width * image.Info.height;
                                    byte  num2       = (_form.GetFullHandModeState()) ? (byte)handData.BodySide : (byte)1;

                                    byte tmp = 0;
                                    for (int i = 0; i < imagesize; i++, numPtr += 4, numPtr2++)
                                    {
                                        tmp       = (byte)(_lut[numPtr2[0]] * num2 * 100);
                                        numPtr[0] = (Byte)(tmp | numPtr[0]);
                                        numPtr[1] = (Byte)(tmp | numPtr[1]);
                                        numPtr[2] = (Byte)(tmp | numPtr[2]);
                                        numPtr[3] = 0xff;
                                    }

                                    labeledBitmap.UnlockBits(bitmapdata);
                                    image.ReleaseAccess(data);
                                }

                                if ((_form.GetContourState()))
                                {
                                    int contourNumber = handData.NumberOfContours;
                                    if (contourNumber > 0)
                                    {
                                        for (int k = 0; k < contourNumber; ++k)
                                        {
                                            IContour contour = handData.Contours[k];
                                            if (contour != null)
                                            {
                                                if (contour.Outer)
                                                {
                                                    pointOuter[j] = contour.Points;
                                                }
                                                else
                                                {
                                                    pointInner[j] = contour.Points;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (labeledBitmap != null)
                    {
                        _form.DisplayBitmap(labeledBitmap);
                        labeledBitmap.Dispose();
                    }
                    if (image != null)
                    {
                        image.Dispose();
                    }

                    for (int i = 0; i < numOfHands; i++)
                    {
                        if (_form.GetContourState())
                        {
                            if (pointOuter[i] != null && pointOuter[i].Length > 0)
                            {
                                _form.DisplayContour(pointOuter[i], i);
                            }
                            if (pointInner[i] != null && pointInner[i].Length > 0)
                            {
                                _form.DisplayContour(pointInner[i], i);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    if (labeledBitmap != null)
                    {
                        labeledBitmap.Dispose();
                    }
                    if (image != null)
                    {
                        image.Dispose();
                    }
                }
            }    //end label image

            //Depth Image
            else
            {
                //collecting 3 images inside a queue and displaying the oldest image
                ImageInfo info;
                Image     image2;
                ImageData imageData = new ImageData();
                info   = image.Info;
                image2 = Image.CreateInstance(_form.session, info, imageData);
                //image2 = _form.g_session. CreateImage(info);
                if (image2 == null)
                {
                    return;
                }
                image2.CopyImage(image);
                _mImages.Enqueue(image2);
                if (_mImages.Count == NumberOfFramesToDelay)
                {
                    System.Drawing.Bitmap depthBitmap;
                    try
                    {
                        depthBitmap = new System.Drawing.Bitmap(image.Info.width, image.Info.height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    }
                    catch (Exception)
                    {
                        image.Dispose();
                        Image queImage = _mImages.Dequeue();
                        queImage.Dispose();
                        return;
                    }

                    ImageData data3;
                    Image     image3 = _mImages.Dequeue();
                    if (image3.AcquireAccess(ImageAccess.ACCESS_READ, PixelFormat.PIXEL_FORMAT_DEPTH, out data3) >= Status.STATUS_NO_ERROR)
                    {
                        float fMaxValue = _maxRange;
                        byte  cVal;

                        var rect       = new System.Drawing.Rectangle(0, 0, image.Info.width, image.Info.height);
                        var bitmapdata = depthBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, depthBitmap.PixelFormat);

                        byte * pDst = (byte *)bitmapdata.Scan0;
                        short *pSrc = (short *)data3.planes[0];
                        int    size = image.Info.width * image.Info.height;

                        for (int i = 0; i < size; i++, pSrc++, pDst += 4)
                        {
                            cVal = (byte)((*pSrc) / fMaxValue * 255);
                            if (cVal != 0)
                            {
                                cVal = (byte)(255 - cVal);
                            }

                            pDst[0] = cVal;
                            pDst[1] = cVal;
                            pDst[2] = cVal;
                            pDst[3] = 255;
                        }
                        try
                        {
                            depthBitmap.UnlockBits(bitmapdata);
                        }
                        catch (Exception)
                        {
                            image3.ReleaseAccess(data3);
                            depthBitmap.Dispose();
                            image3.Dispose();
                            return;
                        }

                        _form.DisplayBitmap(depthBitmap);
                        image3.ReleaseAccess(data3);
                    }
                    depthBitmap.Dispose();
                    image3.Dispose();
                }
            }
        }
コード例 #10
0
        //public IContour[] decomposed(IContour contour)
        //{
        //    for (int i = 0; i < contour.Size; i++)
        //    {
        //        IContour[] cc = decomposed(contour, i);
        //        //оценка.
        //        //рекорд
        //    }

        //}

        public IContour[] decomposed(IContour contour /*, int nom*/)
        {
            points = new List <IPoint>();
            for (int i = 0; i < contour.Size; i++)
            {
                contour[i].accept(this);
            }

            List <IContour> contours   = new List <IContour>();
            double          best_grade = -1;
            int             best_index = 0;

            for (int i = 0; i < 5; i++)
            {
                // Декомпозиция
                // Треугольник

                contours.Add(new Contour(new List <ICurve> {
                    contour[0], contour[1], new Line(points[2], points[0])
                }));

                // Четырёхугольник

                contours.Add(new Contour(new List <ICurve> {
                    contour[2], contour[3], contour[4], new Line(points[0], points[2])
                }));

                // считаем качество
                // Треугольник
                double           contour_grade = 0;
                IMeshGen         generator     = new TriaMeshGen(10, 10);
                List <RegMesh2D> meshs         = generator.Generate(contours[0]);
                foreach (RegMesh2D j in meshs)
                {
                    contour_grade += new ArithmMeanGrade().Calculate(j);
                }

                // Четырёхугольник
                generator      = new QuadCleverMeshGen(10, 10);
                meshs          = generator.Generate(contours[1]);
                contour_grade += new ArithmMeanGrade().Calculate(meshs[0]);
                contour_grade  = contour_grade / 4.0;

                if (contour_grade > best_grade)
                {
                    best_grade = contour_grade;
                    best_index = i;
                }

                // мешаем точки
                IPoint tmp_point = points[0];
                points.RemoveAt(0);
                points.Add(tmp_point);
            }

            // в соответствии с индексом восстанавливаем порядок точек
            for (int i = 0; i < best_index; i++)
            {
                IPoint tmp_point = points[0];
                points.RemoveAt(0);
                points.Add(tmp_point);
            }
            contours.Clear();

            contours.Add(new Contour(new List <ICurve> {
                contour[0], contour[1], new Line(points[2], points[0])
            }));

            contours.Add(new Contour(new List <ICurve> {
                contour[2], contour[3], contour[4], new Line(points[0], points[2])
            }));

            return(contours.ToArray());
        }
コード例 #11
0
ファイル: BasicRegion.cs プロジェクト: virl/fresk
        public override void CutOff(IContour wnd, bool outer)
        {
            List<Point> segments = new List<Point>();

            int inext;
            int iprev;

            foreach (IContour cont in this.Contours)
            {
                for(int i = 0, n = cont.Points.Count - 1; i <= n; ++i)
                {
                    if (i < n)
                    {
                        inext = i + 1;
                    }
                    else
                    {
                        inext = 0;
                    }

                    if (i > 0)
                    {
                        iprev = i - 1;
                    }
                    else
                    {
                        iprev = n;
                    }

                    if (outer)
                    {
                        wnd.CalcSegmentIntersection(
                            cont.Points[i],
                            cont.Points[inext],
                            null,
                            segments
                            );
                    }
                    else
                    {
                        wnd.CalcSegmentIntersection(
                            cont.Points[i],
                            cont.Points[inext],
                            segments,
                            null
                            );
                    }
                }

                for (int i = 0, n = wnd.Points.Count - 1; i <= n; ++i)
                {
                    if (i < n)
                    {
                        inext = i + 1;
                    }
                    else
                    {
                        inext = 0;
                    }

                    if (i > 0)
                    {
                        iprev = i - 1;
                    }
                    else
                    {
                        iprev = n;
                    }

                    cont.CalcSegmentIntersection(
                        wnd.Points[i],
                        wnd.Points[inext],
                        null,
                        segments
                        );
                }

            } // foreach cont

            _contCol.Clear();
            _contCol.AddRange(BasicRegion.GenerateContours(segments));
        }
コード例 #12
0
ファイル: pxcmblobdata.cs プロジェクト: mbahar94/libpxcclr.cs
            /**
                 @brief Retrieve an IContour object using index (that relates to the given order).
                 @param[in] index - the zero-based index of the requested contour (between 0 and QueryNumberOfContours()-1 ).
                 @param[out] contourData - contains the extracted contour line data.
        
                 @return PXCM_STATUS_NO_ERROR - successful operation.
                 @return PXCM_STATUS_DATA_UNAVAILABLE  - index >= number of detected contours. 

                 @see IContour       
             */
            public pxcmStatus QueryContour(Int32 index, out IContour contourData)
            {
                IntPtr cd2;
                pxcmStatus sts = PXCMBlobData_IBlob_QueryContour(instance, index, out cd2);
                contourData = (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) ? new IContour(cd2) : null;
                return sts;
            }
コード例 #13
0
ファイル: RegionBase.cs プロジェクト: virl/fresk
 public abstract void CutOff(IContour wnd, bool outer);
コード例 #14
0
        public IContour[] decomposed(IContour contour)
        {
            Geometry.IPoint[] newPoints  = new Geometry.Point[contour.Size]; //пустой массив для середин линий
            List <IContour>   decFigures = new List <IContour>();            //пустая коллекция для фигур


            for (int i = 0; i < contour.Size; ++i) //находим середины линий
            {
                double x, y;

                contour[i].getPoint(PART, out x, out y);
                newPoints[i] = new Geometry.Point(x, y);
            }

            //поиск точки центра масс
            Geometry.IPoint L = new Geometry.Point((newPoints[0].X + newPoints[1].X + newPoints[2].X) / 3, (newPoints[0].Y + newPoints[1].Y + newPoints[2].Y) / 3);
            MaxPoint = L;
            for (int i = 0; i < contour.Size; ++i) //что это должно делать
            {
                List <ICurve> lines = new List <ICurve>();
                int           index = i == 0 ? newPoints.Length - 1 : i - 1;

                lines.Add(new SubCurve(contour[i], 0, PART));
                lines.Add(new Line(newPoints[i], L));
                lines.Add(new Line(L, newPoints[index]));
                lines.Add(new SubCurve(contour[index], PART, 1));
                decFigures.Add(new Contour(lines));
                //Max += grade.Calculate(gen.Generate(new Contour(lines))[0]);
            }

            /*
             * Max = Max / contour.Size;
             *
             * while (flag == false)
             * {
             *  double Local = 0;
             *  double LocalMax = 0;
             *  IPoint LocalMaxPoint = null;
             *  for (int j = 0; j < 4; j++)
             *  {
             *      switch (j)
             *      {
             *          case 0:
             *              L.X = MaxPoint.X + alpha;
             *              L.Y = MaxPoint.Y;
             *              break;
             *              case 1:
             *              L.X = MaxPoint.X - alpha;
             *              L.Y = MaxPoint.Y;
             *              break;
             *              case 2:
             *              L.X = MaxPoint.X ;
             *              L.Y = MaxPoint.Y + alpha;
             *              break;
             *              case 3:
             *              L.X = MaxPoint.X ;
             *              L.Y = MaxPoint.Y - alpha;
             *              break;
             *      }
             *
             *      for (int i = 0; i < contour.Size; ++i) //что это должно делать
             *      {
             *          List<ICurve> lines = new List<ICurve>();
             *          int index = i == 0 ? newPoints.Length - 1 : i - 1;
             *
             *          lines.Add(new SubCurve(contour[i], 0, PART));
             *          lines.Add(new Line(newPoints[i], L));
             *          lines.Add(new Line(L, newPoints[index]));
             *          lines.Add(new SubCurve(contour[index], PART, 1));
             *          Local += grade.Calculate(gen.Generate(new Contour(lines))[0]);
             *      }
             *      Local = Local / contour.Size;
             *      if (Local > LocalMax)
             *      {
             *          LocalMax = Local;
             *          LocalMaxPoint = L;
             *          Local = 0;
             *      }
             *  }
             *  if (Max - LocalMax < -alpha)
             *  {
             *      Max = LocalMax;
             *      MaxPoint = LocalMaxPoint;
             *  }
             *  else
             *  {
             *      flag = true;
             *  }
             * }
             *
             * for (int i = 0; i < contour.Size; ++i) //что это должно делать
             * {
             *  List<ICurve> lines = new List<ICurve>();
             *  int index = i == 0 ? newPoints.Length - 1 : i - 1;
             *
             *  lines.Add(new SubCurve(contour[i], 0, PART));
             *  lines.Add(new Line(newPoints[i], MaxPoint));
             *  lines.Add(new Line(MaxPoint, newPoints[index]));
             *  lines.Add(new SubCurve(contour[index], PART, 1));
             *  decFigures.Add(new Contour(lines));
             * }
             */
            return(decFigures.ToArray());
        }
コード例 #15
0
 public void Add(IContour contour)
 {
     contours.Add(contour);
 }
コード例 #16
0
ファイル: BasicContour.cs プロジェクト: virl/fresk
 /// <summary>
 /// Добавить точки другого контура, применив
 /// к ним трансформацию.
 /// </summary>
 /// <param name="contour">Контур, из которого копируются точки.</param>
 /// <param name="trans">Трансформация, которая примениться к точкам.</param>
 public void AddWithTransform(IContour contour, Transform trans)
 {
     foreach (Point pnt in contour.Points)
         DrawningPoints.Add(trans.Apply(pnt));
 }
コード例 #17
0
ファイル: Figures.cs プロジェクト: zwcloud/Typography
        //-------
        public void Triangulate <T>(IList <T> contours, List <Poly2Tri.Polygon> outputPolygons)
            where T : IContour
        {
            _waitingHoles.Clear();
            _flattenContours.Clear();

            //--------------------------
            //TODO: review here, add hole or not
            // more than 1 contours, no hole => eg.  i, j, ;,  etc
            // more than 1 contours, with hole => eg.  a,e ,   etc

            //clockwise => not hole

            int cntCount = contours.Count;

            Poly2Tri.Polygon mainPolygon = null;
            //
            //this version if it is a hole=> we add it to main polygon
            //TODO: add to more proper polygon ***
            //eg i
            //--------------------------
            List <Poly2Tri.Polygon> otherPolygons = null;

            for (int n = 0; n < cntCount; ++n)
            {
                IContour cnt = contours[n];

                bool cntIsMainPolygon = cnt.IsClockwise;

                //if (yAxisFlipped)
                //{
                //    cntIsMainPolygon = !cntIsMainPolygon;
                //}

                if (cntIsMainPolygon)
                {
                    //main polygon
                    //not a hole
                    if (mainPolygon == null)
                    {
                        //if we don't have mainPolygon before
                        //this is main polygon
                        mainPolygon = CreatePolygon(cnt);

                        if (_waitingHoles.Count > 0)
                        {
                            //flush all waiting holes to the main polygon
                            int j = _waitingHoles.Count;
                            for (int i = 0; i < j; ++i)
                            {
                                mainPolygon.AddHole(_waitingHoles[i]);
                            }
                            _waitingHoles.Clear();
                        }
                    }
                    else
                    {
                        //if we already have a main polygon
                        //then this is another sub polygon
                        //IsHole is correct after we Analyze() the glyph contour
                        Poly2Tri.Polygon subPolygon = CreatePolygon(cnt);
                        if (otherPolygons == null)
                        {
                            otherPolygons = new List <Poly2Tri.Polygon>();
                        }
                        otherPolygons.Add(subPolygon);
                    }
                }
                else
                {
                    //this is a hole
                    Poly2Tri.Polygon subPolygon = CreatePolygon(cnt);
                    if (mainPolygon == null)
                    {
                        //add to waiting polygon
                        _waitingHoles.Add(subPolygon);
                    }
                    else
                    {
                        //add to mainPolygon
                        mainPolygon.AddHole(subPolygon);
                    }
                }
            }
            if (_waitingHoles.Count > 0)
            {
                throw new NotSupportedException();
            }
            //------------------------------------------
            //2. tri angulate
            Poly2Tri.P2T.Triangulate(mainPolygon); //that poly is triangulated
            outputPolygons.Add(mainPolygon);

            if (otherPolygons != null)
            {
                outputPolygons.AddRange(otherPolygons);
                for (int i = otherPolygons.Count - 1; i >= 0; --i)
                {
                    Poly2Tri.P2T.Triangulate(otherPolygons[i]);
                }
            }
            //------------------------------------------
            _waitingHoles.Clear();
            _flattenContours.Clear();
        }
コード例 #18
0
        private void pictureBox1_Paint (object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            TContourEdit contour = new TContourEdit();
            Random random = new Random();
            int countPoint=0;
            //List<Point> points = new List<Point>();
            for (int i=0; i<2; i++)
            {
                TContourBitEdit contourBitEdit = new TContourBitEdit();
                //for(int y=10; y<100; y*=2)
                //{
                //   int ran = random.Next(100);
                //    contourBitEdit.AddPoint(ran + y*3, i * 2 + ran, 0);
                //   // points.Add(new Point(ran + y * 3, i * 2 + ran));
                //    countPoint++;
                //}
                if(i==0)
                {
                    contourBitEdit.AddPoint(10, 5, 0);
                    contourBitEdit.AddPoint(10, 50, 0);
                    contourBitEdit.AddPoint(50, 100, 0);
                }
               if(i==1)
                {
                    contourBitEdit.AddPoint(150, 150, 0);
                    contourBitEdit.AddPoint(150, 50, 0);
                    contourBitEdit.AddPoint(100, 10, 0);
                }

                if (i % 2 != 0)
                    contourBitEdit.SetClosed(true);
                else
                    contourBitEdit.SetClosed(false);
                contour.AddContourBit(contourBitEdit);
                
            }


            GraphicsPath path = new GraphicsPath();
            for(int i=0; i< contour.GetContourBitCount(); i++)
            {
                Point[] points = new Point[contour.GetContourBit(i).GetPointCount()];
                for (int y = 0; y < contour.GetContourBit(i).GetPointCount(); y++)
                {
                    Point newpoint = new Point((int)contour.GetContourBit(i).GetPoint(y).GetX(), (int)contour.GetContourBit(i).GetPoint(y).GetY());
                    points[y] = newpoint;
                }

                 path.AddLines(points);
            }
            
            Pen myWind = new Pen(Color.Black);
            g.DrawPath(myWind, path);
          
            TRect_Float rect_Float = new TRect_Float();
            rect_Float.X1 = 10;
            rect_Float.X2 = 100;
            rect_Float.Y1 = 10;
            rect_Float.Y2 = 100;
            myWind = new Pen(Color.Red);
            g.DrawRectangle(myWind, new Rectangle((int)rect_Float.TrectAngle()[0].GetX() ,(int)rect_Float.TrectAngle()[0].GetY(), (int)rect_Float.TrectAngle()[2].GetX(), (int)rect_Float.TrectAngle()[2].GetY()));
            Contours contours = new Contours ();
            contours.AddContour(contour);
            IContour contour1 = contour.CutContoursByWindow(contours, rect_Float);
        }