示例#1
0
        //---------------------------------------------------------------------

        private void GenerateAustPlusRandomEllipses(int count)
        {
            subjects.Clear();
            //load map of Australia from resource ...
            _assembly  = Assembly.GetExecutingAssembly();
            polyStream = _assembly.GetManifestResourceStream("GuiDemo.aust.bin");
            int len = (int)polyStream.Length;

            byte[] b = new byte[len];
            polyStream.Read(b, 0, len);
            int polyCnt = BitConverter.ToInt32(b, 0);
            int k       = 4;

            for (int i = 0; i < polyCnt; ++i)
            {
                int vertCnt = BitConverter.ToInt32(b, k);
                k += 4;
                Polygon pg = new Polygon(vertCnt);
                for (int j = 0; j < vertCnt; ++j)
                {
                    float x = BitConverter.ToSingle(b, k) * scale;
                    float y = BitConverter.ToSingle(b, k + 4) * scale;
                    k += 8;
                    pg.Add(new IntPoint((int)x, (int)y));
                }
                subjects.Add(pg);
            }

            clips.Clear();
            Random       rand = new Random();
            GraphicsPath path = new GraphicsPath();
            Point        pt   = new Point();

            const int ellipse_size = 100, margin = 10;

            for (int i = 0; i < count; ++i)
            {
                int w = pictureBox1.ClientRectangle.Width - ellipse_size - margin * 2;
                int h = pictureBox1.ClientRectangle.Height - ellipse_size - margin * 2 - statusStrip1.Height;

                pt.X = rand.Next(w) + margin;
                pt.Y = rand.Next(h) + margin;
                int size = rand.Next(ellipse_size - 20) + 20;
                path.Reset();
                path.AddEllipse(pt.X, pt.Y, size, size);
                path.Flatten();
                Polygon clip = new Polygon(path.PathPoints.Count());
                foreach (PointF p in path.PathPoints)
                {
                    clip.Add(new IntPoint((int)(p.X * scale), (int)(p.Y * scale)));
                }
                clips.Add(clip);
            }
        }
示例#2
0
        void GenerateAustPlusRandomEllipses(int count)
        {
            subjects.Clear();
            //load map of Australia from resource ...
            System.IO.Stream polyStream = Alt.IO.VirtualFile.OpenRead("AltData/Clipper/aust.bin");
            int len = (int)polyStream.Length;

            byte[] b = new byte[len];
            polyStream.Read(b, 0, len);
            int polyCnt = BitConverter.ToInt32(b, 0);
            int k       = 4;

            for (int i = 0; i < polyCnt; ++i)
            {
                int vertCnt = BitConverter.ToInt32(b, k);
                k += 4;
                Polygon pg = new Polygon(vertCnt);
                for (int j = 0; j < vertCnt; ++j)
                {
                    float x = BitConverter.ToSingle(b, k) * scale;
                    float y = BitConverter.ToSingle(b, k + 4) * scale;
                    k += 8;
                    pg.Add(new IntPoint((int)x, (int)y));
                }
                subjects.Add(pg);
            }

            clips.Clear();
            Random       rand = new Random();
            GraphicsPath path = new GraphicsPath();
            PointI       pt   = new PointI();

            const int ellipse_size = 100, margin = 10;

            for (int i = 0; i < count; ++i)
            {
                int w = WorkArea.Width - ellipse_size - margin * 2;
                int h = WorkArea.Height - ellipse_size - margin * 2;

                pt.X = rand.Next(w) + margin;
                pt.Y = rand.Next(h) + margin;
                int size = rand.Next(ellipse_size - 20) + 20;
                path.Reset();
                path.AddEllipse(pt.X, pt.Y, size, size);
                path.Flatten();
                Polygon clip = new Polygon(path.PathPoints.Length);//Count());
                foreach (Point p in path.PathPoints)
                {
                    clip.Add(new IntPoint((int)(p.X * scale), (int)(p.Y * scale)));
                }

                clips.Add(clip);
            }
        }
示例#3
0
        //---------------------------------------------------------------------

        private void GenerateAustPlusRandomEllipses(int count)
        {
            subjects.Clear();
            //load map of Australia from resource ...
            Assembly _assembly = Assembly.GetExecutingAssembly();

            using (BinaryReader polyStream = new BinaryReader(_assembly.GetManifestResourceStream("GuiDemo.aust.bin")))
            {
                int polyCnt = polyStream.ReadInt32();
                for (int i = 0; i < polyCnt; ++i)
                {
                    int     vertCnt = polyStream.ReadInt32();
                    Polygon pg      = new Polygon(vertCnt);
                    for (int j = 0; j < vertCnt; ++j)
                    {
                        float x = polyStream.ReadSingle() * scale;
                        float y = polyStream.ReadSingle() * scale;
                        pg.Add(new IntPoint((int)x, (int)y));
                    }
                    subjects.Add(pg);
                }
            }
            clips.Clear();
            Random rand = new Random();

            using (GraphicsPath path = new GraphicsPath())
            {
                const int ellipse_size = 100, margin = 10;
                for (int i = 0; i < count; ++i)
                {
                    int w = pictureBox1.ClientRectangle.Width - ellipse_size - margin * 2;
                    int h = pictureBox1.ClientRectangle.Height - ellipse_size - margin * 2 - statusStrip1.Height;

                    int x    = rand.Next(w) + margin;
                    int y    = rand.Next(h) + margin;
                    int size = rand.Next(ellipse_size - 20) + 20;
                    path.Reset();
                    path.AddEllipse(x, y, size, size);
                    path.Flatten();
                    Polygon clip = new Polygon(path.PathPoints.Count());
                    foreach (PointF p in path.PathPoints)
                    {
                        clip.Add(new IntPoint((int)(p.X * scale), (int)(p.Y * scale)));
                    }
                    clips.Add(clip);
                }
            }
        }
示例#4
0
        private void ClipPolygons()
        {
            if (Polygons.Count != 2)
            {
                throw new InvalidOperationException("Clipping is only possible for two and exactly two polygons");
            }

            if (Clipper == null)
            {
                throw new InvalidOperationException("No polygon clipper set");
            }

            var resultPolygon = Clipper.GetIntersectedPolygon(Polygons[0].Points, Polygons[1].Points);

            if (resultPolygon.IsEmpty)
            {
                DialogHandler?.ShowMessageBox("No overlap");
            }
            else
            {
                Polygons.Clear();
                var color = GenerateRandomColor();
                Polygons.Add(new Polygon
                {
                    Description = "Clipped Polygon",
                    Points      = resultPolygon,
                    StrokeColor = color,
                    FillColor   = Color.FromArgb(128, color)
                });
            }
        }
示例#5
0
        private void SetPolygons()
        {
            var zc = ZoneContract;

            Polygons.Clear();

            if (zc == null)
            {
                return;
            }

            Polygon poly = new Polygon()
            {
                //FillColor = Color.FromHex(zc.ARGBFill),
                //StrokeColor = Color.FromHex(zc.ARGBFill),
                FillColor   = Color.FromHex(Constants.CardinalRed50ARGB),
                StrokeColor = Color.FromHex(Constants.CardinalRed50ARGB),
                StrokeWidth = 1.0f,
                Tag         = new PolygonTag()
                {
                    PolygonTagType = PolygonTagType.Zone,
                    Tag            = zc.Description
                }
            };

            foreach (var shape in zc.ZoneShapes.Where(z => z.Order > 0).OrderBy(z => z.Order))
            {
                poly.Positions.Add(new Position(shape.Latitude, shape.Longitude));
                //TODO: add code to display negative space
            }
            Polygons.Add(poly);
        }
示例#6
0
        private void GenerateRandomPolygon(int count)
        {
            int    Q    = 10;
            Random rand = new Random();
            int    l    = 10;
            int    t    = 10;
            int    r    = (pictureBox1.ClientRectangle.Width - 20) / Q * Q;
            int    b    = (pictureBox1.ClientRectangle.Height - 20) / Q * Q;

            subjects.Clear();
            clips.Clear();

            Polygon subj = new Polygon(count);

            for (int i = 0; i < count; ++i)
            {
                subj.Add(GenerateRandomPoint(l, t, r, b, rand));
            }
            subjects.Add(subj);

            Polygon clip = new Polygon(count);

            for (int i = 0; i < count; ++i)
            {
                clip.Add(GenerateRandomPoint(l, t, r, b, rand));
            }
            clips.Add(clip);
        }
示例#7
0
 private void ClearPolygon(object obj)
 {
     Pins.Clear();
     Polylines.Clear();
     Polygons.Clear();
     _allowedToAddPoint = true;
 }
示例#8
0
 public void SetClipImage(Image img)
 {
     pictureEdit1.Image = img;
     scaleX             = (double)img.Width / (double)pictureEdit1.Width;
     scaleY             = (double)img.Height / (double)pictureEdit1.Height;
     Polygons.Clear();
     foreach (var point in mClipPolygons)
     {
         //pic to screen
         Console.WriteLine(point[0].X + " " + pictureEdit1.Image.Width);
         var points = PicturePointToScreen(point);
         Polygons.Add(points);
     }
 }
示例#9
0
        public void CreatePolygons()
        {
            Polygons.Clear();

            for (var j = 0; j <= Slices; j++)
            {
                var angleJ  = j * 360.0 / (double)Slices;
                var angleJ2 = (j + 1) * 360.0 / (double)Slices;

                for (var i = 0; i <= Stacks; i++)
                {
                    var angleI  = i * 180.0 / (double)Stacks;
                    var angleI2 = (i + 1) * 180.0 / (double)Stacks;

                    var A = Spherical(Radius, angleI, angleJ);
                    var B = Spherical(Radius, angleI, angleJ2);
                    var C = Spherical(Radius, angleI2, angleJ2);
                    var D = Spherical(Radius, angleI2, angleJ);

                    var polygon = new GLPolygon(A, B, C, D);
                    polygon.Texture = Texture;

                    var textCoordLeft  = (j) * (1.0 / Slices);
                    var textCoordRight = (j + 1) * (1.0 / Slices);

                    var textCoordTop    = (i) * (1.0 / Stacks);
                    var textCoordBottom = (i + 1) * (1.0 / Stacks);

                    var coords = new List <GLTexCoord>();

                    coords.Add(new GLTexCoord(textCoordLeft, textCoordTop));
                    coords.Add(new GLTexCoord(textCoordRight, textCoordTop));
                    coords.Add(new GLTexCoord(textCoordRight, textCoordBottom));
                    coords.Add(new GLTexCoord(textCoordLeft, textCoordBottom));


                    polygon.SetPolygonTexCoords(coords);

                    Polygons.Add(polygon);
                }
            }
        }
        private async Task RefreshPolygonsAsync()
        {
            if (_visibleRegion == null)
            {
                return;
            }
            int layer = _hexagonal.CalculateLayerFromCameraPositionZoom(_currentCameraIdledEventArgs.Position.Zoom);

            if (layer != _layerLast)
            {
                Polygons.Clear();
                _layerLast = layer;
            }
            _hexagonal.Initialize(_currentCameraIdledEventArgs.Position.Target.Latitude, _currentCameraIdledEventArgs.Position.Target.Longitude, layer);
            for (int row = -2; row < 3; ++row)
            {
                for (int col = -2; col < 3; ++col)
                {
                    var poly = _hexagonal.HexagonalPolygon(_hexagonal.CenterLocation, col, row);
                    if (Polygons.Any(p => p.PolygonTagEquals(poly)))
                    {
                        continue;
                    }
                    int heatCount = _layerService.NumberOfUsersInsidePolygonTag(poly.ExtractPolygonTag().Tag);
                    poly.FillColor   = _heatGradientService.SteppedColor(heatCount);
                    poly.IsClickable = true;
                    poly.Clicked    += Polygon_Clicked;
                    if (poly.PolygonTagStringEquals(_currentPositionTag))
                    {
                        poly.StrokeColor = Color.Coral;
                        poly.StrokeWidth = 5;
                    }
                    else
                    {
                        poly.StrokeColor = _heatGradientService.SteppedColor(heatCount + 1);
                        poly.StrokeWidth = 1;
                    }
                    Polygons.Add(poly);
                }
            }
            await RefreshZonesAsync();
        }
示例#11
0
        private void GeneratePolygons()
        {
            Polygons.Clear();

            Polygons.Add(new GLPolygon(  // top
                             new GLPoint(_size / 2, _size / 2, -_size / 2),
                             new GLPoint(-_size / 2, _size / 2, -_size / 2),
                             new GLPoint(-_size / 2, _size / 2, _size / 2),
                             new GLPoint(_size / 2, _size / 2, _size / 2)
                             ));
            Polygons.Add(new GLPolygon(  // bottom
                             new GLPoint(_size / 2, -_size / 2, _size / 2),
                             new GLPoint(-_size / 2, -_size / 2, _size / 2),
                             new GLPoint(-_size / 2, -_size / 2, -_size / 2),
                             new GLPoint(_size / 2, -_size / 2, -_size / 2)
                             ));
            Polygons.Add(new GLPolygon(  // front
                             new GLPoint(_size / 2, _size / 2, _size / 2),
                             new GLPoint(-_size / 2, _size / 2, _size / 2),
                             new GLPoint(-_size / 2, -_size / 2, _size / 2),
                             new GLPoint(_size / 2, -_size / 2, _size / 2)
                             ));
            Polygons.Add(new GLPolygon(  // back
                             new GLPoint(_size / 2, -_size / 2, -_size / 2),
                             new GLPoint(-_size / 2, -_size / 2, -_size / 2),
                             new GLPoint(-_size / 2, _size / 2, -_size / 2),
                             new GLPoint(_size / 2, _size / 2, -_size / 2)
                             ));
            Polygons.Add(new GLPolygon(  // left
                             new GLPoint(-_size / 2, _size / 2, _size / 2),
                             new GLPoint(-_size / 2, _size / 2, -_size / 2),
                             new GLPoint(-_size / 2, -_size / 2, -_size / 2),
                             new GLPoint(-_size / 2, -_size / 2, _size / 2)
                             ));
            Polygons.Add(new GLPolygon(  // right
                             new GLPoint(_size / 2, _size / 2, -_size / 2),
                             new GLPoint(_size / 2, _size / 2, _size / 2),
                             new GLPoint(_size / 2, -_size / 2, _size / 2),
                             new GLPoint(_size / 2, -_size / 2, -_size / 2)
                             ));
        }
示例#12
0
        PushPolygonToArray(List <List <IntPoint> > subjects, List <List <IntPoint> > clips)
        {
            Polygons nextClip              = new Polygons();
            Polygons currentSubject        = new Polygons();
            Polygons currentClip           = new Polygons();
            Polygons currentArrayDraw      = new Polygons();
            Polygons currentArrayInvisible = new Polygons();
            Clipper  cTupleDraw            = new Clipper();
            Clipper  cTupleInvisible       = new Clipper();

            //find polygons to be drawn
            currentSubject.Clear();
            currentClip.Clear();
            currentSubject = subjects;
            currentClip    = clips;
            cTupleDraw.Clear();
            cTupleDraw.AddPaths(currentSubject, PolyType.ptSubject, true);
            cTupleDraw.AddPaths(currentClip, PolyType.ptClip, true);
            currentArrayDraw.Clear();
            bool succeededDraw = cTupleDraw.Execute(ClipType.ctDifference, currentArrayDraw,
                                                    PolyFillType.pftNonZero, PolyFillType.pftNonZero);

            //find next clipped polygon
            nextClip.Clear();
            bool succeededNextClip = cTupleDraw.Execute(ClipType.ctUnion, nextClip,
                                                        PolyFillType.pftNonZero, PolyFillType.pftNonZero);

            //find invisible polygons
            cTupleInvisible.Clear();
            cTupleInvisible.AddPaths(currentSubject, PolyType.ptSubject, true);
            cTupleInvisible.AddPaths(currentClip, PolyType.ptClip, true);
            currentArrayInvisible.Clear();
            bool succeededInvisible = cTupleInvisible.Execute(ClipType.ctIntersection, currentArrayInvisible,
                                                              PolyFillType.pftNonZero, PolyFillType.pftNonZero);

            return(new Tuple <List <List <IntPoint> >, List <List <IntPoint> >, List <List <IntPoint> > >
                       (currentArrayDraw, currentArrayInvisible, nextClip));
        }
示例#13
0
        //---------------------------------------------------------------------

        public void GenerateRandomPolygon(int count)
        {
            try
            {
                int    Q    = 10;
                Random rand = new Random();
                int    l    = 10;
                int    t    = 10;
                int    r    = (pictureBox1.ClientRectangle.Width - 20) / Q * Q;
                int    b    = (pictureBox1.ClientRectangle.Height - 20) / Q * Q;

                subjects.Clear();
                clips.Clear();

                Polygon subj = new Polygon();
                for (int i = 0; i < count; ++i)
                {
                    subj.Add(GenerateRandomPoint(l, t, r, b, rand));
                }
                subjects.Add(subj);

                Polygon clip = new Polygon();
                for (int i = 0; i < count; ++i)
                {
                    clip.Add(GenerateRandomPoint(l, t, r, b, rand));
                }
                clips.Add(clip);

                //Testing
                //https://www.c-sharpcorner.com/article/dependency-injection-using-unity-resolve-dependency-of-dependencies/
                //throw new Exception("Test ILogger by Dependency Injection");
            }
            catch (Exception ex)
            {
                _ILogger.Log(ex);
            }
        }
示例#14
0
        void DrawingPanel_Paint(object sender, GUI.PaintEventArgs e)
        {
            GUI.Cursor.Current = GUI.Cursors.WaitCursor;

            Graphics      graphics            = e.Graphics;
            SmoothingMode fillSmoothingMode   = graphics is SoftwareGraphics ? SmoothingMode.AntiAlias : SmoothingMode.None;
            SmoothingMode strokeSmoothingMode = SmoothingMode.AntiAlias;

            graphics.SmoothingMode = fillSmoothingMode;

            graphics.Clear(Color.White);


            GraphicsPath path = new GraphicsPath();

            if (rbNonZero.IsChecked)
            {
                path.FillMode = FillMode.Winding;
            }

            //draw subjects ...
            foreach (Polygon pg in subjects)
            {
                Point[] pts = PolygonToPointArray(pg, scale);
                path.AddPolygon(pts);
                pts = null;
            }

            Pen myPen = new Pen(
                //Color.FromArgb(196, 0xC3, 0xC9, 0xCF),
                Color.FromArgb(128, 0, 0, 255),
                0.6);
            SolidColorBrush myBrush = new SolidColorBrush(
                //Color.FromArgb(127, 0xDD, 0xDD, 0xF0));
                //Color.FromArgb(255, 210, 210, 255));
                Color.FromArgb(127, Color.LightBlue));

            graphics.SmoothingMode = fillSmoothingMode;
            graphics.FillPath(myBrush, path);
            graphics.SmoothingMode = strokeSmoothingMode;
            graphics.DrawPath(myPen, path);
            path.Reset();

            //draw clips ...
            if (rbNonZero.IsChecked)
            {
                path.FillMode = FillMode.Winding;
            }
            foreach (Polygon pg in clips)
            {
                Point[] pts = PolygonToPointArray(pg, scale);
                path.AddPolygon(pts);
                pts = null;
            }
            myPen.Color   = Color.FromArgb(128, Color.Red); //0xF9, 0xBE, 0xA6);
            myBrush.Color =                                 //Color.FromArgb(127, 0xFF, 0xE0, 0xE0);
                            Color.FromArgb(50, 255, 0, 0);

            graphics.SmoothingMode = fillSmoothingMode;
            graphics.FillPath(myBrush, path);
            graphics.SmoothingMode = strokeSmoothingMode;
            graphics.DrawPath(myPen, path);

            //do the clipping ...
            if ((clips.Count > 0 || subjects.Count > 0) &&
                !rbNone.IsChecked)
            {
                Polygons solution2 = new Polygons();
                Clipper  c         = new Clipper(0);
                c.AddPaths(subjects, PolyType.ptSubject, true);
                c.AddPaths(clips, PolyType.ptClip, true);
                solution.Clear();
                bool succeeded = c.Execute(GetClipType(), solution, GetPolyFillType(), GetPolyFillType());
                if (succeeded)
                {
                    myBrush.Color = Color.Black;
                    path.Reset();

                    //It really shouldn't matter what FillMode is used for solution
                    //polygons because none of the solution polygons overlap.
                    //However, FillMode.Winding will show any orientation errors where
                    //holes will be stroked (outlined) correctly but filled incorrectly  ...
                    path.FillMode = FillMode.Winding;

                    //or for something fancy ...
                    if (nudOffset.Value != 0)
                    {
                        //old   solution2 = Clipper.OffsetPolygons(solution, (double)nudOffset.Value * scale, JoinType.jtMiter);
                        ClipperOffset co = new ClipperOffset(2, 0.25);
                        co.AddPaths(solution, JoinType.jtMiter, EndType.etClosedPolygon);
                        co.Execute(ref solution2, (double)nudOffset.Value * scale);
                    }
                    else
                    {
                        solution2 = new Polygons(solution);
                    }

                    foreach (Polygon pg in solution2)
                    {
                        Point[] pts = PolygonToPointArray(pg, scale);
                        if (pts.Length//Count()
                            > 2)
                        {
                            path.AddPolygon(pts);
                        }
                        pts = null;
                    }
                    //myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
                    myBrush.Color = Color.FromArgb(100, 0, 255, 0);
                    myPen.Color   = Color.FromArgb(255, 0, 0x33, 0);
                    myPen.Width   = 1;

                    graphics.SmoothingMode = fillSmoothingMode;
                    graphics.FillPath(myBrush, path);
                    graphics.SmoothingMode = strokeSmoothingMode;
                    graphics.DrawPath(myPen, path);

                    //now do some fancy testing ...
                    Font   f = new Font("Arial", 8);
                    Brush  b = Brushes.Navy;
                    double subj_area = 0, clip_area = 0, int_area = 0, union_area = 0;
                    c.Clear();
                    c.AddPaths(subjects, PolyType.ptSubject, true);
                    c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2)
                    {
                        subj_area += Clipper.Area(pg);
                    }
                    c.Clear();
                    c.AddPaths(clips, PolyType.ptClip, true);
                    c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2)
                    {
                        clip_area += Clipper.Area(pg);
                    }
                    c.AddPaths(subjects, PolyType.ptSubject, true);
                    c.Execute(ClipType.ctIntersection, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2)
                    {
                        int_area += Clipper.Area(pg);
                    }
                    c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2)
                    {
                        union_area += Clipper.Area(pg);
                    }

                    StringFormat lftStringFormat = new StringFormat();
                    lftStringFormat.Alignment     = StringAlignment.Near;
                    lftStringFormat.LineAlignment = StringAlignment.Near;
                    StringFormat rtStringFormat = new StringFormat();
                    rtStringFormat.Alignment     = StringAlignment.Far;
                    rtStringFormat.LineAlignment = StringAlignment.Near;
                    RectI rec = new RectI(WorkArea.Width - 114, WorkArea.Height - 116, 104, 106);
                    graphics.FillRectangle(new SolidColorBrush(Color.FromArgb(196, Color.WhiteSmoke)), rec);
                    graphics.DrawRectangle(myPen, rec);
                    rec.Inflate(new SizeI(-2, 0));

                    //  because of Alt.Sketch smaller top offset
                    rec += new PointI(0, 1);
                    rec -= new SizeI(0, 1);

                    graphics.DrawString("Areas", f, b, rec, rtStringFormat);
                    rec.Offset(new PointI(0, 14));
                    graphics.DrawString("subj: ", f, b, rec, lftStringFormat);
                    graphics.DrawString((subj_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new PointI(0, 12));
                    graphics.DrawString("clip: ", f, b, rec, lftStringFormat);
                    graphics.DrawString((clip_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new PointI(0, 12));
                    graphics.DrawString("intersect: ", f, b, rec, lftStringFormat);
                    graphics.DrawString((int_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new PointI(0, 12));
                    graphics.DrawString("---------", f, b, rec, rtStringFormat);
                    rec.Offset(new PointI(0, 10));
                    graphics.DrawString("s + c - i: ", f, b, rec, lftStringFormat);
                    graphics.DrawString(((subj_area + clip_area - int_area) / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new PointI(0, 10));
                    graphics.DrawString("---------", f, b, rec, rtStringFormat);
                    rec.Offset(new PointI(0, 10));
                    graphics.DrawString("union: ", f, b, rec, lftStringFormat);
                    graphics.DrawString((union_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new PointI(0, 10));
                    graphics.DrawString("---------", f, b, rec, rtStringFormat);
                } //end if succeeded
            }     //end if something to clip

            //TEMP  pictureBox1.Image = mybitmap;
            graphics.Dispose();
            GUI.Cursor.Current = GUI.Cursors.Default;
        }
示例#15
0
        public void DrawBitmap(float scale, PictureBox pictureBox1, RadioButton rbNone, RadioButton rbIntersect, RadioButton rbUnion, RadioButton rbDifference, RadioButton rbXor, Polygons clips, Polygons subjects, Polygons solution, Bitmap mybitmap, bool justClip = false)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form1 form = DependencyInjector.Retrieve <Form1>();

            try
            {
                if (!justClip)
                {
                    form.GenerateRandomPolygon((int)Constants.NudCount);
                }
                using (Graphics newgraphic = Graphics.FromImage(mybitmap))
                    using (GraphicsPath path = new GraphicsPath())
                    {
                        newgraphic.SmoothingMode = SmoothingMode.AntiAlias;
                        newgraphic.Clear(Color.White);

                        path.FillMode = FillMode.Winding;

                        //draw subjects ...
                        foreach (Polygon pg in subjects)
                        {
                            PointF[] pts = Form1.PolygonToPointFArray(pg, scale);
                            path.AddPolygon(pts);
                            pts = null;
                        }
                        using (Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6))
                            using (SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0)))
                            {
                                newgraphic.FillPath(myBrush, path);
                                newgraphic.DrawPath(myPen, path);
                                path.Reset();

                                path.FillMode = FillMode.Winding;

                                foreach (Polygon pg in clips)
                                {
                                    PointF[] pts = Form1.PolygonToPointFArray(pg, scale);
                                    path.AddPolygon(pts);
                                    pts = null;
                                }
                                myPen.Color   = Color.FromArgb(196, 0xF9, 0xBE, 0xA6);
                                myBrush.Color = Color.FromArgb(127, 0xFF, 0xE0, 0xE0);
                                newgraphic.FillPath(myBrush, path);
                                newgraphic.DrawPath(myPen, path);

                                //do the clipping ...
                                if ((clips.Count > 0 || subjects.Count > 0) && !rbNone.Checked)
                                {
                                    List <List <IntPoint> > solution2 = new List <List <IntPoint> >();
                                    Clipper c = new Clipper();
                                    c.AddPaths(subjects, PolyType.ptSubject, true);
                                    c.AddPaths(clips, PolyType.ptClip, true);
                                    solution.Clear();
#if UsePolyTree
                                    bool succeeded = c.Execute(GetClipType(), solutionTree, GetPolyFillType(), GetPolyFillType());
                                    //nb: we aren't doing anything useful here with solutionTree except to show
                                    //that it works. Convert PolyTree back to Polygons structure ...
                                    Clipper.PolyTreeToPolygons(solutionTree, solution);
#else
                                    ClipType clipType;
                                    if (rbIntersect.Checked)
                                    {
                                        clipType = ClipType.ctIntersection;
                                    }
                                    else if (rbUnion.Checked)
                                    {
                                        clipType = ClipType.ctUnion;
                                    }
                                    else if (rbDifference.Checked)
                                    {
                                        clipType = ClipType.ctDifference;
                                    }
                                    else if (rbXor.Checked)
                                    {
                                        clipType = ClipType.ctXor;
                                    }
                                    else
                                    {
                                        clipType = ClipType.ctXor;
                                    }

                                    bool succeeded = c.Execute(clipType, solution, form.GetPolyFillType(), form.GetPolyFillType());
#endif
                                    if (succeeded)
                                    {
                                        //SaveToFile("solution", solution);
                                        myBrush.Color = Color.Black;
                                        path.Reset();

                                        //It really shouldn't matter what FillMode is used for solution
                                        //polygons because none of the solution polygons overlap.
                                        //However, FillMode.Winding will show any orientation errors where
                                        //holes will be stroked (outlined) correctly but filled incorrectly  ...
                                        path.FillMode = FillMode.Winding;

                                        //or for something fancy ...

                                        if (Constants.NudOffset != 0)
                                        {
                                            ClipperOffset co = new ClipperOffset();
                                            co.AddPaths(solution, JoinType.jtRound, EndType.etClosedPolygon);
                                            co.Execute(ref solution2, (double)Constants.NudOffset * scale);
                                        }
                                        else
                                        {
                                            solution2 = new List <List <IntPoint> >(solution);
                                        }

                                        foreach (List <IntPoint> pg in solution2)
                                        {
                                            PointF[] pts = Form1.PolygonToPointFArray(pg, scale);
                                            if (pts.Count() > 2)
                                            {
                                                path.AddPolygon(pts);
                                            }
                                            pts = null;
                                        }
                                        myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
                                        myPen.Color   = Color.FromArgb(255, 0, 0x33, 0);
                                        myPen.Width   = 1.0f;
                                        newgraphic.FillPath(myBrush, path);
                                        newgraphic.DrawPath(myPen, path);

                                        //now do some fancy testing ...
                                        using (Font f = new Font("Arial", 8))
                                            using (SolidBrush b = new SolidBrush(Color.Navy))
                                            {
                                                double subj_area = 0, clip_area = 0, int_area = 0, union_area = 0;
                                                c.Clear();
                                                c.AddPaths(subjects, PolyType.ptSubject, true);
                                                c.Execute(ClipType.ctUnion, solution2, form.GetPolyFillType(), form.GetPolyFillType());
                                                foreach (List <IntPoint> pg in solution2)
                                                {
                                                    subj_area += Clipper.Area(pg);
                                                }
                                                c.Clear();
                                                c.AddPaths(clips, PolyType.ptClip, true);
                                                c.Execute(ClipType.ctUnion, solution2, form.GetPolyFillType(), form.GetPolyFillType());
                                                foreach (List <IntPoint> pg in solution2)
                                                {
                                                    clip_area += Clipper.Area(pg);
                                                }
                                                c.AddPaths(subjects, PolyType.ptSubject, true);
                                                c.Execute(ClipType.ctIntersection, solution2, form.GetPolyFillType(), form.GetPolyFillType());
                                                foreach (List <IntPoint> pg in solution2)
                                                {
                                                    int_area += Clipper.Area(pg);
                                                }
                                                c.Execute(ClipType.ctUnion, solution2, form.GetPolyFillType(), form.GetPolyFillType());
                                                foreach (List <IntPoint> pg in solution2)
                                                {
                                                    union_area += Clipper.Area(pg);
                                                }

                                                using (StringFormat lftStringFormat = new StringFormat())
                                                    using (StringFormat rtStringFormat = new StringFormat())
                                                    {
                                                        lftStringFormat.Alignment     = StringAlignment.Near;
                                                        lftStringFormat.LineAlignment = StringAlignment.Near;
                                                        rtStringFormat.Alignment      = StringAlignment.Far;
                                                        rtStringFormat.LineAlignment  = StringAlignment.Near;
                                                        Rectangle rec = new Rectangle(pictureBox1.ClientSize.Width - 108,
                                                                                      pictureBox1.ClientSize.Height - 116, 104, 106);
                                                        newgraphic.FillRectangle(new SolidBrush(Color.FromArgb(196, Color.WhiteSmoke)), rec);
                                                        newgraphic.DrawRectangle(myPen, rec);
                                                        rec.Inflate(new Size(-2, 0));
                                                        newgraphic.DrawString("Areas", f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 14));
                                                        newgraphic.DrawString("subj: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString((subj_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 12));
                                                        newgraphic.DrawString("clip: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString((clip_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 12));
                                                        newgraphic.DrawString("intersect: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString((int_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 12));
                                                        newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 10));
                                                        newgraphic.DrawString("s + c - i: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString(((subj_area + clip_area - int_area) / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 10));
                                                        newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 10));
                                                        newgraphic.DrawString("union: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString((union_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 10));
                                                        newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                                                    }
                                            }
                                    } //end if succeeded
                                }     //end if something to clip
                                pictureBox1.Image = mybitmap;
                            }
                    }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
示例#16
0
文件: Book.cs 项目: ernado-legacy/Owl
 public virtual void Clear()
 {
     Polygons.Clear();
 }
示例#17
0
        //---------------------------------------------------------------------------



        private void DrawBitmap(bool justClip = false)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                if (!justClip)
                {
                    //GenerateRandomPolygon(10);
                    //GenerateTestPolygon(4);
                }
                using (Graphics newgraphic = Graphics.FromImage(mybitmap))
                    using (GraphicsPath path = new GraphicsPath())
                    {
                        newgraphic.SmoothingMode = SmoothingMode.AntiAlias;
                        newgraphic.Clear(Color.White);
                        if (rbNonZero.Checked)
                        {
                            path.FillMode = FillMode.Winding;
                        }

                        //draw subjects ...
                        foreach (Polygon pg in subjects)
                        {
                            PointF[] pts = PolygonToPointFArray(pg, scale);
                            path.AddPolygon(pts);
                            pts = null;
                        }
                        using (Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6))
                            using (SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0)))
                            {
                                newgraphic.FillPath(myBrush, path);
                                newgraphic.DrawPath(myPen, path);
                                path.Reset();

                                //draw clips ...
                                if (rbNonZero.Checked)
                                {
                                    path.FillMode = FillMode.Winding;
                                }
                                foreach (Polygon pg in clips)
                                {
                                    PointF[] pts = PolygonToPointFArray(pg, scale);
                                    path.AddPolygon(pts);
                                    pts = null;
                                }
                                myPen.Color   = Color.FromArgb(196, 0xF9, 0xBE, 0xA6);
                                myBrush.Color = Color.FromArgb(127, 0xFF, 0xE0, 0xE0);
                                newgraphic.FillPath(myBrush, path);
                                newgraphic.DrawPath(myPen, path);


                                //do the clipping ...
                                if ((clips.Count > 0 || subjects.Count > 0) && !rbNone.Checked)
                                {
                                    Polygons solution2 = new Polygons();
                                    Clipper  c         = new Clipper();
                                    c.AddPaths(subjects, PolyType.ptSubject, true);
                                    c.AddPaths(clips, PolyType.ptClip, true);
                                    solution.Clear();

                                    //my codes ...

                                    bool succeeded = c.Execute(GetClipType(), solution, GetPolyFillType(), GetPolyFillType());
                                    PrintVertice(solution);
                                    //if (rbIntersect.Checked)
                                    //    Console.WriteLine("****END OF INTERSECT****");
                                    //if (rbUnion.Checked)
                                    //    Console.WriteLine("****END OF UNION****");
                                    //if (rbDifference.Checked)
                                    //    Console.WriteLine("****END OF DIFFERENCE****");
                                    //else
                                    //    Console.WriteLine("****END OF XOR****");
                                    Tuple <List <List <IntPoint> >, List <List <IntPoint> >, List <List <IntPoint> > > testTuple;

                                    testTuple = PushPolygonToArray(subjects, clips);

                                    //my codes ...


                                    if (succeeded)
                                    {
                                        //SaveToFile("solution", solution);
                                        myBrush.Color = Color.Black;
                                        path.Reset();

                                        //It really shouldn't matter what FillMode is used for solution
                                        //polygons because none of the solution polygons overlap.
                                        //However, FillMode.Winding will show any orientation errors where
                                        //holes will be stroked (outlined) correctly but filled incorrectly  ...
                                        path.FillMode = FillMode.Winding;

                                        //or for something fancy ...

                                        if (nudOffset.Value != 0)
                                        {
                                            ClipperOffset co = new ClipperOffset();
                                            co.AddPaths(solution, JoinType.jtRound, EndType.etClosedPolygon);
                                            co.Execute(ref solution2, (double)nudOffset.Value * scale);
                                        }
                                        else
                                        {
                                            solution2 = new Polygons(solution);
                                        }

                                        foreach (Polygon pg in solution2)
                                        {
                                            PointF[] pts = PolygonToPointFArray(pg, scale);
                                            if (pts.Count() > 2)
                                            {
                                                path.AddPolygon(pts);
                                            }
                                            pts = null;
                                        }
                                        myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
                                        myPen.Color   = Color.FromArgb(255, 0, 0x33, 0);
                                        myPen.Width   = 1.0f;
                                        newgraphic.FillPath(myBrush, path);
                                        newgraphic.DrawPath(myPen, path);

                                        //now do some fancy testing ...
                                        using (Font f = new Font("Arial", 8))
                                            using (SolidBrush b = new SolidBrush(Color.Navy))
                                            {
                                                double subj_area = 0, clip_area = 0, int_area = 0, union_area = 0;
                                                c.Clear();
                                                c.AddPaths(subjects, PolyType.ptSubject, true);
                                                c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                                                foreach (Polygon pg in solution2)
                                                {
                                                    subj_area += Clipper.Area(pg);
                                                }
                                                c.Clear();
                                                c.AddPaths(clips, PolyType.ptClip, true);
                                                c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                                                foreach (Polygon pg in solution2)
                                                {
                                                    clip_area += Clipper.Area(pg);
                                                }
                                                c.AddPaths(subjects, PolyType.ptSubject, true);
                                                c.Execute(ClipType.ctIntersection, solution2, GetPolyFillType(), GetPolyFillType());
                                                foreach (Polygon pg in solution2)
                                                {
                                                    int_area += Clipper.Area(pg);
                                                }
                                                c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                                                foreach (Polygon pg in solution2)
                                                {
                                                    union_area += Clipper.Area(pg);
                                                }

                                                using (StringFormat lftStringFormat = new StringFormat())
                                                    using (StringFormat rtStringFormat = new StringFormat())
                                                    {
                                                        lftStringFormat.Alignment     = StringAlignment.Near;
                                                        lftStringFormat.LineAlignment = StringAlignment.Near;
                                                        rtStringFormat.Alignment      = StringAlignment.Far;
                                                        rtStringFormat.LineAlignment  = StringAlignment.Near;
                                                        Rectangle rec = new Rectangle(pictureBox1.ClientSize.Width - 108,
                                                                                      pictureBox1.ClientSize.Height - 116, 104, 106);
                                                        newgraphic.FillRectangle(new SolidBrush(Color.FromArgb(196, Color.WhiteSmoke)), rec);
                                                        newgraphic.DrawRectangle(myPen, rec);
                                                        rec.Inflate(new Size(-2, 0));
                                                        newgraphic.DrawString("Areas", f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 14));
                                                        newgraphic.DrawString("subj: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString((subj_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 12));
                                                        newgraphic.DrawString("clip: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString((clip_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 12));
                                                        newgraphic.DrawString("intersect: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString((int_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 12));
                                                        newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 10));
                                                        newgraphic.DrawString("s + c - i: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString(((subj_area + clip_area - int_area) / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 10));
                                                        newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 10));
                                                        newgraphic.DrawString("union: ", f, b, rec, lftStringFormat);
                                                        newgraphic.DrawString((union_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                                                        rec.Offset(new Point(0, 10));
                                                        newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                                                    }
                                            }
                                    } //end if succeeded
                                }     //end if something to clip
                                pictureBox1.Image = mybitmap;
                            }
                    }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
示例#18
0
        //---------------------------------------------------------------------------

        private void DrawBitmap(bool justClip = false)
        {
            if (!justClip)
            {
                if (rbTest2.Checked)
                {
                    GenerateAustPlusRandomEllipses((int)nudCount.Value);
                }
                else
                {
                    GenerateRandomPolygon((int)nudCount.Value);
                }
            }

            Cursor.Current = Cursors.WaitCursor;
            Graphics newgraphic;

            newgraphic = Graphics.FromImage(mybitmap);
            newgraphic.SmoothingMode = SmoothingMode.AntiAlias;
            newgraphic.Clear(Color.White);

            GraphicsPath path = new GraphicsPath();

            if (rbNonZero.Checked)
            {
                path.FillMode = FillMode.Winding;
            }

            //draw subjects ...
            foreach (Polygon pg in subjects)
            {
                PointF[] pts = PolygonToPointFArray(pg, scale);
                path.AddPolygon(pts);
                pts = null;
            }
            Pen        myPen   = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
            SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));

            newgraphic.FillPath(myBrush, path);
            newgraphic.DrawPath(myPen, path);
            path.Reset();

            //draw clips ...
            if (rbNonZero.Checked)
            {
                path.FillMode = FillMode.Winding;
            }
            foreach (Polygon pg in clips)
            {
                PointF[] pts = PolygonToPointFArray(pg, scale);
                path.AddPolygon(pts);
                pts = null;
            }
            myPen.Color   = Color.FromArgb(196, 0xF9, 0xBE, 0xA6);
            myBrush.Color = Color.FromArgb(127, 0xFF, 0xE0, 0xE0);
            newgraphic.FillPath(myBrush, path);
            newgraphic.DrawPath(myPen, path);

            //do the clipping ...
            if ((clips.Count > 0 || subjects.Count > 0) && !rbNone.Checked)
            {
                Polygons solution2 = new Polygons();
                Clipper  c         = new Clipper();
                c.AddPolygons(subjects, PolyType.ptSubject);
                c.AddPolygons(clips, PolyType.ptClip);
                exSolution.Clear();
                solution.Clear();
                bool succeeded = c.Execute(GetClipType(), solution, GetPolyFillType(), GetPolyFillType());
                if (succeeded)
                {
                    myBrush.Color = Color.Black;
                    path.Reset();

                    //It really shouldn't matter what FillMode is used for solution
                    //polygons because none of the solution polygons overlap.
                    //However, FillMode.Winding will show any orientation errors where
                    //holes will be stroked (outlined) correctly but filled incorrectly  ...
                    path.FillMode = FillMode.Winding;

                    //or for something fancy ...
                    if (nudOffset.Value != 0)
                    {
                        solution2 = Clipper.OffsetPolygons(solution, (double)nudOffset.Value * scale, JoinType.jtMiter);
                    }
                    else
                    {
                        solution2 = new Polygons(solution);
                    }
                    foreach (Polygon pg in solution2)
                    {
                        PointF[] pts = PolygonToPointFArray(pg, scale);
                        if (pts.Count() > 2)
                        {
                            path.AddPolygon(pts);
                        }
                        pts = null;
                    }
                    myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
                    myPen.Color   = Color.FromArgb(255, 0, 0x33, 0);
                    myPen.Width   = 1.0f;
                    newgraphic.FillPath(myBrush, path);
                    newgraphic.DrawPath(myPen, path);

                    //now do some fancy testing ...
                    Font       f = new Font("Arial", 8);
                    SolidBrush b = new SolidBrush(Color.Navy);
                    double     subj_area = 0, clip_area = 0, int_area = 0, union_area = 0;
                    c.Clear();
                    c.AddPolygons(subjects, PolyType.ptSubject);
                    c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2)
                    {
                        subj_area += Clipper.Area(pg);
                    }
                    c.Clear();
                    c.AddPolygons(clips, PolyType.ptClip);
                    c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2)
                    {
                        clip_area += Clipper.Area(pg);
                    }
                    c.AddPolygons(subjects, PolyType.ptSubject);
                    c.Execute(ClipType.ctIntersection, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2)
                    {
                        int_area += Clipper.Area(pg);
                    }
                    c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2)
                    {
                        union_area += Clipper.Area(pg);
                    }

                    StringFormat lftStringFormat = new StringFormat();
                    lftStringFormat.Alignment     = StringAlignment.Near;
                    lftStringFormat.LineAlignment = StringAlignment.Near;
                    StringFormat rtStringFormat = new StringFormat();
                    rtStringFormat.Alignment     = StringAlignment.Far;
                    rtStringFormat.LineAlignment = StringAlignment.Near;
                    Rectangle rec = new Rectangle(pictureBox1.ClientSize.Width - 108,
                                                  pictureBox1.ClientSize.Height - 116, 104, 106);
                    newgraphic.FillRectangle(new SolidBrush(Color.FromArgb(196, Color.WhiteSmoke)), rec);
                    newgraphic.DrawRectangle(myPen, rec);
                    rec.Inflate(new Size(-2, 0));
                    newgraphic.DrawString("Areas", f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 14));
                    newgraphic.DrawString("subj: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString((subj_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 12));
                    newgraphic.DrawString("clip: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString((clip_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 12));
                    newgraphic.DrawString("intersect: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString((int_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 12));
                    newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 10));
                    newgraphic.DrawString("s + c - i: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString(((subj_area + clip_area - int_area) / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 10));
                    newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 10));
                    newgraphic.DrawString("union: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString((union_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 10));
                    newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                } //end if succeeded
            }     //end if something to clip

            pictureBox1.Image = mybitmap;
            newgraphic.Dispose();
            Cursor.Current = Cursors.Default;
        }
示例#19
0
        public FestaMapRootPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator, IShowFestaMap showFesta, IMapAssociated mapParam)
        {
            _eventAggregator   = eventAggregator;
            _navigationService = navigationService;
            showFestaUsecase   = showFesta;
            _mapParams         = mapParam;

            InfoWindowClickedCommand = new DelegateCommand <InfoWindowClickedEventArgs>(async(pin) =>
            {
                var region = pin.Pin.Tag as MapRegion;
                if (region == null)
                {
                    return;
                }
                if (IsGlobalMap)
                {
                    if (region.MapObjectType.HasFlag(MapObjectEnum.STAGE))
                    {
                        await _navigationService.NavigateAsync(
                            nameof(StageEventListRootPageViewModel).GetViewNameFromRule(),
                            StageEventListRootPageViewModel.GetNavigationParameter(region.Id, region.Name));
                    }
                    else
                    {
                        var type = region.MapObjectType.HasFlag(MapObjectEnum.EXHIBITION) ? PlanningTypeEnum.EXHIBITION : PlanningTypeEnum.STALL;
                        await _navigationService.NavigateAsync(
                            "RegionSpecificPlanningListPage",
                            PlanningListRootPageViewModel.GetNavigationParameter(region.Id, region.Name, type));
                    }
                }
            });

            _eventAggregator.GetEvent <PolygonClickedEvent>().Subscribe((pin) =>
            {
                SelectedPin.Value = pin.Tag as Pin;
                MoveToRegionRequest.MoveToRegion(
                    MapSpan.FromCenterAndRadius(SelectedPin.Value.Position, Distance.FromMeters(100)));
            }).AddTo(this.Disposable);

            showFesta.Pins.ToCollectionChanged <Pin>()
            .Subscribe(change =>
            {
                switch (change.Action)
                {
                case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                    Pins?.Add(change.Value);
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                    Pins?.Remove(change.Value);
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                    Pins?.Clear();
                    break;
                }
            }).AddTo(this.Disposable);

            showFesta.Polygons.ToCollectionChanged <Polygon>()
            .Subscribe(change =>
            {
                switch (change.Action)
                {
                case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                    Polygons?.Add(change.Value);
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                    Polygons?.Remove(change.Value);
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                    Polygons?.Clear();
                    break;
                }
            }).AddTo(this.Disposable);

            // For iOS
            _eventAggregator.GetEvent <TabbedPageOpendEvent>().Subscribe((ev) =>
            {
                if (ev.Name != this.GetType().Name.Replace("ViewModel", ""))
                {
                    return;
                }

                IsShowingUser.Value = true;
                showFestaUsecase.InitializeAllMapObjects();
                if (IsGlobalMap)
                {
                    MoveToRegionRequest.MoveToRegion(
                        MapSpan.FromCenterAndRadius(
                            new Position(_mapParams.MapCenterLangitude, _mapParams.MapCenterLongitude),
                            Distance.FromMeters(185)));
                }
            }).AddTo(this.Disposable);

            _eventAggregator.GetEvent <LocationPermissionRequestResultEvent>()
            .Subscribe((ev) =>
            {
                IsShowingUser.Value = ev.Granted;
            });

            Title.AddTo(this.Disposable);
            SelectedPin.AddTo(this.Disposable);
            IsShowingUser.AddTo(this.Disposable);
        }
示例#20
0
      //------------------------------------------------------------------------------

      public static void PolyTreeToPolygons(PolyTree polytree, Polygons polys)
      {
        polys.Clear();
        polys.Capacity = polytree.Total;
        AddPolyNodeToPaths(polytree, NodeType.ntAny, polys);
      }
示例#21
0
        public void generateRooms(int width, int height, bool sym = true)
        {
            rooms.Clear();
            decoration.Clear();

            int[,] grid = new int[width, height];

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    grid[x, y] = 0;
                }
            }

            int    scale   = (int)Math.Min(canvas.RenderSize.Width / (width + 6), canvas.RenderSize.Height / (height + 6));
            double mid     = canvas.RenderSize.Height / 2;
            int    offsetX = (int)((canvas.RenderSize.Width - scale * width) / 2);
            int    offsetY = (int)((canvas.RenderSize.Height - scale * height) / 2);

            int hh = height;

            if (sym)
            {
                hh = (height + 1) / 2;
            }

            for (int y = 0; y < hh; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    double u = 1.0 - Math.Abs(2.0 * y - height) / height;
                    double v = width * (0.2 + 0.3 * u);
                    double w = (x < v ? x / v : (width - x) / (width - v));
                    double p = (0.05 + 0.95 * w) * (0.25 + 0.75 * u);

                    if (rnd.NextDouble() < p)
                    {
                        grid[x, y] = -1;
                        if (sym)
                        {
                            grid[x, height - y - 1] = -1;
                        }
                    }
                }
            }

            for (int i = 0; i < 2; ++i)
            {
                int[,] temp = new int[width, height];

                for (int y = 0; y < height; ++y)
                {
                    for (int x = 0; x < width; ++x)
                    {
                        int count = 0;

                        for (int v = -1; v <= 1; ++v)
                        {
                            for (int u = -1; u <= 1; ++u)
                            {
                                if (u == 0 && v == 0)
                                {
                                    continue;
                                }

                                int dx = x + u;
                                int dy = y + v;

                                if (dx < 0 || dx >= width || dy < 0 || dy >= height)
                                {
                                    continue;
                                }

                                count += (grid[dx, dy] == -1 ? 1 : 0);
                            }
                        }

                        temp[x, y] = count;
                    }
                }

                for (int y = 0; y < height; ++y)
                {
                    for (int x = 0; x < width; ++x)
                    {
                        if (temp[x, y] == 2 || temp[x, y] == 5 || temp[x, y] == 7)
                        {
                            grid[x, y] = -1;
                        }
                        else if (temp[x, y] == 3 && grid[x, y] == 0)
                        {
                            grid[x, y] = -1;
                        }
                        else if ((temp[x, y] == 1 || temp[x, y] == 6 || temp[x, y] == 8) && grid[x, y] == -1)
                        {
                            grid[x, y] = -1;
                        }
                        else if (grid[x, y] == -1)
                        {
                            grid[x, y] = -2;
                        }
                        else
                        {
                            grid[x, y] = 0;
                        }
                    }
                }
            }

            //Temporary
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    if (grid[x, y] != 0)
                    {
                        AddRectRoom(offsetX + scale * x, offsetY + scale * y, scale, scale);
                    }
                }
            }
        }
示例#22
0
            PushPolygonToArray(List<List<IntPoint>> subjects, List<List<IntPoint>> clips)
        {
            Polygons nextClip = new Polygons();
            Polygons currentSubject = new Polygons();
            Polygons currentClip = new Polygons();
            Polygons currentArrayDraw = new Polygons();
            Polygons currentArrayInvisible = new Polygons();
            Clipper cTupleDraw = new Clipper();
            Clipper cTupleInvisible = new Clipper();

            //find polygons to be drawn
            currentSubject.Clear();
            currentClip.Clear();
            currentSubject = subjects;
            currentClip = clips;
            cTupleDraw.Clear();
            cTupleDraw.AddPaths(currentSubject, PolyType.ptSubject, true);
            cTupleDraw.AddPaths(currentClip, PolyType.ptClip, true);
            currentArrayDraw.Clear();
            bool succeededDraw = cTupleDraw.Execute(ClipType.ctDifference, currentArrayDraw,
                PolyFillType.pftNonZero, PolyFillType.pftNonZero);

            //find next clipped polygon
            nextClip.Clear();
            bool succeededNextClip = cTupleDraw.Execute(ClipType.ctUnion, nextClip,
                PolyFillType.pftNonZero, PolyFillType.pftNonZero);

            //find invisible polygons
            cTupleInvisible.Clear();
            cTupleInvisible.AddPaths(currentSubject, PolyType.ptSubject, true);
            cTupleInvisible.AddPaths(currentClip, PolyType.ptClip, true);
            currentArrayInvisible.Clear();
            bool succeededInvisible = cTupleInvisible.Execute(ClipType.ctIntersection, currentArrayInvisible,
                PolyFillType.pftNonZero, PolyFillType.pftNonZero);

            return new Tuple<List<List<IntPoint>>, List<List<IntPoint>>, List<List<IntPoint>>>
                (currentArrayDraw, currentArrayInvisible, nextClip);
        }
示例#23
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            if (null == doc)
            {
                Util.ErrorMsg("Please run this command in a valid"
                              + " Revit project document.");
                return(Result.Failed);
            }

            ICollection <ElementId> ids
                = Util.GetSelectedElements(uidoc);

            if ((null == ids) || (0 == ids.Count))
            {
                return(Result.Cancelled);
            }

            // Third attempt: create the element 2D outline
            // from element solid faces and meshes in current
            // view by projecting them onto the XY plane and
            // executing 2d Boolean unions on them.

            View view = doc.ActiveView;

            Options opt = new Options
            {
                View = view
            };

            Clipper                   c      = new Clipper();
            VertexLookup              vl     = new VertexLookup();
            List <LineSegment>        curves = new List <LineSegment>();
            Polygons                  union  = new Polygons();
            Dictionary <int, JtLoops> booleanLoops
                = new Dictionary <int, JtLoops>(ids.Count);

            foreach (ElementId id in ids)
            {
                Element         e   = doc.GetElement(id);
                GeometryElement geo = e.get_Geometry(opt);

                c.Clear();
                vl.Clear();
                union.Clear();

                AddToUnion(union, curves, vl, c, geo);

                //AddToUnion( union, vl, c, curves );

                //c.AddPaths( subjects, PolyType.ptSubject, true );
                //c.AddPaths( clips, PolyType.ptClip, true );

                bool succeeded = c.Execute(ClipType.ctUnion, union,
                                           PolyFillType.pftPositive, PolyFillType.pftPositive);

                if (0 == union.Count)
                {
                    Debug.Print(string.Format(
                                    "No outline found for {0} <{1}>",
                                    e.Name, e.Id.IntegerValue));
                }
                else
                {
                    JtLoops loops = ConvertToLoops(union);

                    loops.NormalizeLoops();

                    booleanLoops.Add(id.IntegerValue, loops);
                }
            }

            string filepath = Path.Combine(Util.OutputFolderPath,
                                           doc.Title + "_element_2d_boolean_outline.json");

            JtWindowHandle hwnd = new JtWindowHandle(uiapp.MainWindowHandle);

            string caption = doc.Title + " 2D Booleans";

            Util.ExportLoops(filepath, hwnd, caption,
                             doc, booleanLoops);

            return(Result.Succeeded);
        }
示例#24
0
        //---------------------------------------------------------------------

        bool LoadFromFile(string filename, Polygons ppg, double scale = 0,
                          int xOffset = 0, int yOffset = 0)
        {
            double scaling = Math.Pow(10, scale);

            ppg.Clear();
            if (!File.Exists(filename))
            {
                return(false);
            }
            using (StreamReader sr = new StreamReader(filename))
            {
                string line;
                if ((line = sr.ReadLine()) == null)
                {
                    return(false);
                }
                int polyCnt, vertCnt;
                if (!Int32.TryParse(line, out polyCnt) || polyCnt < 0)
                {
                    return(false);
                }
                ppg.Capacity = polyCnt;
                for (int i = 0; i < polyCnt; i++)
                {
                    if ((line = sr.ReadLine()) == null)
                    {
                        return(false);
                    }
                    if (!Int32.TryParse(line, out vertCnt) || vertCnt < 0)
                    {
                        return(false);
                    }
                    Polygon pg = new Polygon();
                    ppg.Add(pg);
                    for (int j = 0; j < vertCnt; j++)
                    {
                        double x, y;
                        if ((line = sr.ReadLine()) == null)
                        {
                            return(false);
                        }
                        char[]   delimiters = new char[] { ',', ' ' };
                        string[] vals       = line.Split(delimiters);
                        if (vals.Length < 2)
                        {
                            return(false);
                        }
                        if (!double.TryParse(vals[0], out x))
                        {
                            return(false);
                        }
                        if (!double.TryParse(vals[1], out y))
                        {
                            if (vals.Length < 2 || !double.TryParse(vals[2], out y))
                            {
                                return(false);
                            }
                        }
                        x = x * scaling + xOffset;
                        y = y * scaling + yOffset;
                        pg.Add(new IntPoint((int)Math.Round(x), (int)Math.Round(y)));
                    }
                }
            }
            return(true);
        }
示例#25
0
        //------------------------------------------------------------------------------

        private void BuildResult(Polygons polyg)
        {
            polyg.Clear();
            polyg.Capacity = m_PolyOuts.Count;
            for (int i = 0; i < m_PolyOuts.Count; i++)
            {
                OutRec outRec = m_PolyOuts[i];
                if (outRec.pts == null) continue;
                OutPt p = outRec.pts;
                int cnt = PointCount(p);
                if (cnt < 3) continue;
                Polygon pg = new Polygon(cnt);
                for (int j = 0; j < cnt; j++)
                {
                    pg.Add(p.pt);
                    p = p.prev;
                }
                polyg.Add(pg);
            }
        }
示例#26
0
        //---------------------------------------------------------------------

        bool LoadFromFile(string filename, Polygons ppg, double scale = 0,
          int xOffset = 0, int yOffset = 0)
        {
            double scaling = Math.Pow(10, scale);
            ppg.Clear();
            if (!File.Exists(filename)) return false;
            StreamReader sr = new StreamReader(filename);
            if (sr == null) return false;
            string line;
            if ((line = sr.ReadLine()) == null) return false;
            int polyCnt, vertCnt;
            if (!Int32.TryParse(line, out polyCnt) || polyCnt < 0) return false;
            ppg.Capacity = polyCnt;
            for (int i = 0; i < polyCnt; i++)
            {
                if ((line = sr.ReadLine()) == null) return false;
                if (!Int32.TryParse(line, out vertCnt) || vertCnt < 0) return false;
                Polygon pg = new Polygon(vertCnt);
                ppg.Add(pg);
                for (int j = 0; j < vertCnt; j++)
                {
                    double x, y;
                    if ((line = sr.ReadLine()) == null) return false;
                    char[] delimiters = new char[] { ',', ' ' };
                    string [] vals = line.Split(delimiters);
                    if (vals.Length < 2) return false;
                    if (!double.TryParse(vals[0], out x)) return false;
                    if (!double.TryParse(vals[1], out y))
                        if (vals.Length < 2 || !double.TryParse(vals[2], out y)) return false;
                    x = x * scaling + xOffset;
                    y = y * scaling + yOffset;
                    pg.Add(new IntPoint((int)Math.Round(x), (int)Math.Round(y)));
                }
            }
            return true;
        }
示例#27
0
 public void Clear()
 {
     Markers.Clear();
     Routes.Clear();
     Polygons.Clear();
 }
示例#28
0
        //------------------------------------------------------------------------------

        public bool Execute(ClipType clipType, Polygons solution,
            PolyFillType subjFillType, PolyFillType clipFillType)
        {
            if (m_ExecuteLocked) return false;
            m_ExecuteLocked = true;
            solution.Clear();
            m_SubjFillType = subjFillType;
            m_ClipFillType = clipFillType;
            m_ClipType = clipType;
            m_UsingPolyTree = false;
            bool succeeded = ExecuteInternal();
            //build the return polygons ...
            if (succeeded) BuildResult(solution);
            m_ExecuteLocked = false;
            return succeeded;
        }
示例#29
0
        GetElementLoops(
            View view,
            ICollection <ElementId> ids)
        {
            Document doc = view.Document;

            Options opt = new Options
            {
                View = view
            };

            Clipper                   c      = new Clipper();
            VertexLookup              vl     = new VertexLookup();
            List <LineSegment>        curves = new List <LineSegment>();
            Polygons                  union  = new Polygons();
            Dictionary <int, JtLoops> booleanLoops
                = new Dictionary <int, JtLoops>(ids.Count);

            foreach (ElementId id in ids)
            {
                c.Clear();
                vl.Clear();
                union.Clear();

                Element e = doc.GetElement(id);

                if (e is Room)
                {
                    IList <IList <BoundarySegment> > boundary
                        = (e as Room).GetBoundarySegments(
                              new SpatialElementBoundaryOptions());

                    // Ignore all loops except first, which is
                    // hopefully outer -- and hopefully the room
                    // does not have several disjunct parts.

                    AddToUnionRoom(union, curves, vl, c, boundary);
                }
                else
                {
                    GeometryElement geo = e.get_Geometry(opt);
                    AddToUnion(union, curves, vl, c, geo);
                }

                //AddToUnion( union, vl, c, curves );

                //c.AddPaths( subjects, PolyType.ptSubject, true );
                //c.AddPaths( clips, PolyType.ptClip, true );

                bool succeeded = c.Execute(ClipType.ctUnion, union,
                                           PolyFillType.pftPositive, PolyFillType.pftPositive);

                if (0 == union.Count)
                {
                    Debug.Print(string.Format(
                                    "No outline found for {0} <{1}>",
                                    e.Name, e.Id.IntegerValue));
                }
                else
                {
                    JtLoops loops = ConvertToLoops(union);

                    loops.NormalizeLoops();

                    booleanLoops.Add(id.IntegerValue, loops);
                }
            }
            return(booleanLoops);
        }
示例#30
0
        //------------------------------------------------------------------------------

        public static void PolyTreeToPolygons(PolyTree polytree, Polygons polygons)
        {
            polygons.Clear();
            polygons.Capacity = polytree.Total;
            AddPolyNodeToPolygons(polytree, polygons);
        }
示例#31
0
 /// <summary>
 /// Setter for setting polygons to a complex polygon.
 /// </summary>
 /// <param name="polygons">List of polygons.</param>
 public void SetPolygons(List <Polygon> polygons)
 {
     Polygons.Clear();
     Polygons.AddRange(polygons);
 }