Beispiel #1
0
 private void FillVectorCloud(VectorCloud2D cloud, Vector2D v, Rectangle2D bb)
 {
     if (bb.IsInside(v))
     {
         cloud.Add(v);
     }
 }
Beispiel #2
0
 private void CreateLinesFromPointCloud(VectorImage image, VectorCloud2D cloud)
 {
     for (int i = 0; i < cloud.Count - 1; i++)
     {
         image.Add(new Line2D(cloud[i], cloud[i + 1]));
     }
 }
        private static VectorCloud2D CreateLinkedVectorCloud(List <Line2D> shapeLineList)
        {
            VectorCloud2D vc = new VectorCloud2D();

            for (int i = 0; i < shapeLineList.Count; i++)
            {
                vc.Add(shapeLineList[i].Start);
            }
            return(vc);
        }
Beispiel #4
0
        public VectorCloud2D ReadPointCloud(int count)
        {
            VectorCloud2D cloud = new VectorCloud2D();

            for (int i = 0; i < count; i++)
            {
                cloud.Add(ReadPoint());
            }
            return(cloud);
        }
Beispiel #5
0
        public static VectorCloud2D Create(Rectangle2D rect, int count)
        {
            VectorCloud2D pointCloud = new VectorCloud2D();
            Random        r          = new Random();

            for (int i = 0; i < count; i++)
            {
                pointCloud.Add(RandVec2D(rect, r));
            }
            return(pointCloud);
        }
Beispiel #6
0
 private void FillVectorCloud(VectorCloud2D cloud, Line2D l, Rectangle2D bb)
 {
     if (bb.IsInside(l.Start))
     {
         cloud.Add(l.Start);
     }
     if (bb.IsInside(l.End))
     {
         cloud.Add(l.End);
     }
 }
Beispiel #7
0
        public static VectorCloud2D CreateCirulairCloud(Circle2D c, int count)
        {
            VectorCloud2D pointCloud = new VectorCloud2D();
            Random        r          = new Random();

            for (int i = 0; i < count; i++)
            {
                pointCloud.Add((RandVec2D(r).Normal() * c.radius) + c.center);
            }
            pointCloud.Add(c.center);
            return(pointCloud);
        }
Beispiel #8
0
        public static VectorCloud2D CreatSquareCloud(int rowCount, int columnCount)
        {
            VectorCloud2D pointCloud = new VectorCloud2D();
            Random        r          = new Random();

            for (int yy = 0; yy < rowCount; yy++)
            {
                for (int xx = 0; xx < columnCount; xx++)
                {
                    pointCloud.Add(new Vector2D(xx * 10, yy * 10));
                }
            }
            return(pointCloud);
        }
Beispiel #9
0
        public void Execute(IVectorImageProvider imageProvider)
        {
            bool          hasIntersections = false;
            VectorCloud2D cloud            = new VectorCloud2D(imageProvider.CurrImage.GetPrimitives <Vector2D>());

            for (int i = 0; i < cloud.Count - 2; i++)
            {
                Vector2D v1 = cloud[i];
                Vector2D v2 = cloud[i + 1];
                Vector2D v3 = cloud[i + 2];

                int countEqual = 0;
                if (v1.IsPositionEqual(v2))
                {
                    countEqual++;
                }
                if (v1.IsPositionEqual(v3))
                {
                    countEqual++;
                }
                if (v2.IsPositionEqual(v3))
                {
                    countEqual++;
                }
                bool isJumpLine = countEqual > 0;
                if (isJumpLine)
                {
                    imageProvider.CurrImage.Add(new Line2D(v1, v2));
                    imageProvider.CurrImage.Add(new Line2D(v2, v3));
                    imageProvider.CurrImage.Add(new Line2D(v3, v1));
                }
                else
                {
                    Triangle2D t = new Triangle2D(v1, v2, v3);
                    if (CheckTriangleListIntersection(imageProvider.CurrImage, t))
                    {
                        hasIntersections = true;
                        PrimitiveRenderData.Get(t).Color   = Color.Lime;
                        PrimitiveRenderData.Get(t.a).Color = Color.Lime;
                        PrimitiveRenderData.Get(t.b).Color = Color.Lime;
                        PrimitiveRenderData.Get(t.c).Color = Color.Lime;
                    }
                    imageProvider.CurrImage.Add(t);
                }
            }
            if (hasIntersections)
            {
                MessageBox.Show("Has intersections!!!!!!");
            }
        }
Beispiel #10
0
        public static void PointInTriangleTest(VectorImage image)
        {
            Triangle2D t = new Triangle2D(new Vector2D(25, 150), new Vector2D(200, 200), new Vector2D(60, 80));

            image.Add(t);
            VectorCloud2D pc = PointCloudCreator.Create(new Rectangle2D(new Vector2D(10, 10), new Vector2D(300, 300)), 500);

            pc.Add(t.a);
            pc.Add(t.b);
            pc.Add(t.c);

            foreach (Vector2D p in pc)
            {
                p.SetData(new PrimitiveRenderData(t.IsInside(p) ? Color.DarkGreen : Color.DarkRed));
            }

            image.Add(pc);
        }
Beispiel #11
0
        public VectorCloud2D GetPointsAtLoction(Vector2D loc, double offset)
        {
            Rectangle2D   r      = new Rectangle2D(loc - offset, loc + offset);
            VectorCloud2D result = new VectorCloud2D();

            for (int i = 0; i < primitives.Count; i++)
            {
                if (primitives[i] is Vector2D)
                {
                    FillVectorCloud(result, primitives[i] as Vector2D, r);
                }
                else if (primitives[i] is Line2D)
                {
                    FillVectorCloud(result, primitives[i] as Line2D, r);
                }
            }
            result.SortByDistance(loc);
            return(result);
        }
Beispiel #12
0
        internal static void BuildImage(VectorImage image, LevelReader level, double scale)
        {
            VectorCloud2D vc = new VectorCloud2D();

            for (int i = 0; i < level.vertices.Count; i++)
            {
                vc.Add(new Vector2D(level.vertices[i].x, level.vertices[i].y));
            }

            Dictionary <int, List <Line2D> > sectors = new Dictionary <int, List <Line2D> >();
            List <Line2D> lines = new List <Line2D>();

            foreach (LineDefType l in level.lineDefs)
            {
                Line2D line = new Line2D(vc[l.startVertex], vc[l.endVertex]);

                if (l.IsSecret)
                {
                    PrimitiveRenderData.Get(line).Color = Color.Yellow;
                }
                else if (l.IsTwoSided)
                {
                    PrimitiveRenderData.Get(line).Color = Color.SandyBrown;
                }
                else
                {
                    PrimitiveRenderData.Get(line).Color = Color.Red;
                }

                lines.Add(line);

                AddLineToSector(sectors, level, l.rightSideDef, line);
                AddLineToSector(sectors, level, l.leftSideDef, line);
            }

            image.primitives.AddRange(vc);
            image.primitives.AddRange(lines);

            MakeShapesFromSectors(image, sectors);
        }
Beispiel #13
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                dragLocation  = new Point(e.X, e.Y);
                dragMouseLock = true;
            }
            if (e.Button == MouseButtons.Left)
            {
                Vector2D loc        = renderContext.ScreenToPoint(e.X, e.Y);
                Vector2D snappedLoc = loc;
                if (snapToGridPermanentButton.Checked)
                {
                    snappedLoc = renderContext.GridSnap(loc);
                }

                switch (editAction)
                {
                case EditAction.ActionMovePoints:
                {
                    List <Primitive2D> prims = CurrImage.GetPrimitivesAtLocation(loc, 4.0f / renderContext.DrawScale);

                    if (prims.Count == 0)
                    {
                        if (!multiselect)
                        {
                            mouseWasMovedAfterClick = false;
                        }
                    }
                    else
                    {
                        mouseWasMovedAfterClick = true;
                        if (!multiselect)
                        {
                            selection.Clear();
                            selection.Add(prims[0]);
                        }
                        else
                        {
                            selection.TogglePrimitive(prims[0]);
                        }
                    }
                    break;
                }

                case EditAction.ActionAddPoints:
                {
                    CurrImage.primitives.Add(new Vector2D(snappedLoc));
                    break;
                }

                case EditAction.ActionAddLines:
                {
                    if (linkObject != null)
                    {
                        ObjectLinker.EndLinkingObjects(CurrImage.GetLinkablePrimitives(), loc, linkObject);
                        linkObject = null;
                        renderPanel.Render();
                        return;
                    }
                    else
                    {
                        linkObject = ObjectLinker.StartLinkingObjects(CurrImage.GetLinkablePrimitives(), loc);
                        if (linkObject != null)
                        {
                            renderPanel.Render();
                            return;
                        }
                    }



                    VectorCloud2D dots = CurrImage.GetPointsAtLoction(loc, 4.0f / renderContext.DrawScale);
                    Vector2D      dot;
                    if (dots.Count == 0)
                    {
                        dot = new Vector2D(snappedLoc);
                        CurrImage.primitives.Add(dot);
                    }
                    else
                    {
                        dot = dots[0];
                    }

                    if (lineStartPoint != null)
                    {
                        // Line is ready, connect!
                        CurrImage.primitives.Add(new Line2D(lineStartPoint, dot));
                        lineStartPoint = null;
                    }
                    else
                    {
                        // First dot, draw dummy line
                        lineStartPoint = dot;
                    }
                    break;
                }
                }
            }
            renderPanel.Render();
        }
        //private List<Contstraint> constraints = new List<Contstraint>();

        public DelaunayTriangulation(VectorCloud2D originalPointCloud)
        {
            this.originalPointCloud = originalPointCloud;
            pointCloud.AddRange(originalPointCloud);
            pointCloud.Sort((a, b) => (a.x != b.x) ? a.x.CompareTo(b.x) : a.y.CompareTo(b.y));
        }