Пример #1
0
        public void TestCellsCount()
        {
            List<Segment> input = new List<Segment>();
            input.Add(new Segment(0, 0, 0, 10));
            input.Add(new Segment(0, 10, 10, 10));
            input.Add(new Segment(10, 10, 10, 0));
            input.Add(new Segment(10, 0, 0, 0));
            input.Add(new Segment(0, 0, 5, 5));
            input.Add(new Segment(5, 5, 10, 10));

            //Build the CLR voronoi
            VoronoiWrapper vw = new VoronoiWrapper();
            foreach (var s in input)
                vw.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);

            vw.ConstructVoronoi();
            List<Tuple<int, int, bool, bool, List<int>, bool, short>> clrCells = vw.GetCells();

            //Build the C# Voronoi
            BoostVoronoi bv = new BoostVoronoi();
            foreach (var s in input)
                bv.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);
            bv.Construct();
            List<Cell> sharpCells = bv.Cells;

            //Test that the outputs have the same length
            Assert.AreEqual(clrCells.Count, sharpCells.Count);
        }
Пример #2
0
        public void TestTupleCells()
        {
            VoronoiWrapper vw = new VoronoiWrapper();
            vw.AddSegment(0, 0, 0, 10);
            vw.AddSegment(0, 10, 10, 10);
            vw.AddSegment(10, 10, 10, 0);
            vw.AddSegment(10, 0, 0, 0);
            vw.AddSegment(0, 0, 5, 5);
            vw.AddSegment(5, 5, 10, 10);
            vw.ConstructVoronoi();

            List<Tuple<double, double>> vertices = vw.GetVertices();
            List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges();
            List<Tuple<int, int, bool, bool, List<int>, bool, short>> cells = vw.GetCells();

            for (int i = 0; i < vertices.Count; i++)
            {
                TestContext.WriteLine(String.Format("Vertex {0}. X: {1}, Y: {2}", i, vertices[i].Item1, vertices[i].Item2));
            }

            foreach (var c in cells)
            {
                foreach (var s in c.Item5)
                {
                        TestContext.WriteLine(String.Format("Cell: {0}, Segment: {1}, Start: {2}, End: {3}", c.Item1, s, edges[s].Item2, edges[s].Item3));
                }
            }
            Assert.AreEqual(11, cells.Count);
        }
Пример #3
0
        /// <summary>
        /// Add a segment to the list of input segments
        /// </summary>
        /// <param name="x1">X coordinate of the start point</param>
        /// <param name="y1">Y coordinate of the start point</param>
        /// <param name="x2">X coordinate of the end point</param>
        /// <param name="y2">Y coordinate of the end point</param>
        //public void AddSegment(int x1, int y1, int x2, int y2)
        //{
        //    InputSegments.Add(new Segment(x1 * ScaleFactor,y1 * ScaleFactor,x2 * ScaleFactor,y2 * ScaleFactor));
        //}


        /// <summary>
        /// Add a segment to the list of input segments
        /// </summary>
        /// <param name="x1">X coordinate of the start point</param>
        /// <param name="y1">Y coordinate of the start point</param>
        /// <param name="x2">X coordinate of the end point</param>
        /// <param name="y2">Y coordinate of the end point</param>
        public void AddSegment(double x1, double y1, double x2, double y2)
        {
            Segment s = new Segment(
                Convert.ToInt32(x1 * ScaleFactor),
                Convert.ToInt32(y1 * ScaleFactor),
                Convert.ToInt32(x2 * ScaleFactor),
                Convert.ToInt32(y2 * ScaleFactor)
                );

            InputSegments[InputSegments.Count] = s;
            VoronoiWrapper.AddSegment(
                s.Start.X,
                s.Start.Y,
                s.End.X,
                s.End.Y
                );
        }
Пример #4
0
        public void TestCellEndNodes()
        {
            VoronoiWrapper vw = new VoronoiWrapper();
            vw.AddSegment(0, 0, 0, 10);
            vw.AddSegment(0, 10, 10, 10);
            vw.AddSegment(10, 10, 10, 0);
            vw.AddSegment(10, 0, 0, 0);
            vw.AddSegment(0, 0, 5, 5);
            vw.AddSegment(5, 5, 10, 10);
            vw.ConstructVoronoi();

            List<Tuple<double, double>> vertices = vw.GetVertices();
            List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges();
            List<Tuple<int, int, bool, bool, List<int>, bool, short>> cells = vw.GetCells();

            foreach (var c in cells)
            {
                //Get first edge and last edge
                Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>> firstEdge = edges[c.Item5[0]];
                Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>> lastEdge = edges[c.Item5[c.Item5.Count -1]];

                Assert.AreEqual(firstEdge.Item2, lastEdge.Item3);
            }
        }
Пример #5
0
        public void TestVerticesSequence()
        {
            List<Segment> input = new List<Segment>();
            input.Add(new Segment(0, 0, 0, 10));
            input.Add(new Segment(0, 10, 10, 10));
            input.Add(new Segment(10, 10, 10, 0));
            input.Add(new Segment(10, 0, 0, 0));
            input.Add(new Segment(0, 0, 5, 5));
            input.Add(new Segment(5, 5, 10, 10));

            //Build the CLR voronoi
            VoronoiWrapper vw = new VoronoiWrapper();
            foreach (var s in input)
                vw.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);

            vw.ConstructVoronoi();
            List<Tuple<double, double>> clrVertices = vw.GetVertices();

            //Build the C# Voronoi
            BoostVoronoi bv = new BoostVoronoi();
            foreach (var s in input)
                bv.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);
            bv.Construct();
            List<Vertex> sharpVertices = bv.Vertices;

            //Test that the outputs have the same length
            Assert.AreEqual(clrVertices.Count, sharpVertices.Count);

            for (int i = 0; i < sharpVertices.Count; i++)
            {
                Assert.AreEqual(clrVertices[i].Item1, sharpVertices[i].X);
                Assert.AreEqual(clrVertices[i].Item2, sharpVertices[i].Y);
            }
        }
Пример #6
0
        public void TestSegmentTwin()
        {
            List<Point> inputPoint = new List<Point>() { new Point(5, 5) };
            List<Segment> inputSegment = new List<Segment>();
            inputSegment.Add(new Segment(0, 0, 0, 10));
            inputSegment.Add(new Segment(0, 10, 10, 10));
            inputSegment.Add(new Segment(10, 10, 10, 0));
            inputSegment.Add(new Segment(10, 0, 0, 0));

            //Build the CLR voronoi
            VoronoiWrapper vw = new VoronoiWrapper();

            foreach (var p in inputPoint)
                vw.AddPoint(p.X, p.Y);

            foreach (var s in inputSegment)
                vw.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);

            vw.ConstructVoronoi();
            List<Tuple<int, int, bool, bool, List<int>, bool, short>> clrCells = vw.GetCells();

            //Build the C# Voronoi
            BoostVoronoi bv = new BoostVoronoi();
            foreach (var p in inputPoint)
                bv.AddPoint(p.X, p.Y);
            foreach (var s in inputSegment)
                bv.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);

            bv.Construct();
            List<Edge> sharpEdges = bv.Edges;

            //Test twin reciprocity
            for (int i = 0; i < sharpEdges.Count; i++)
            {
                Assert.AreEqual(i, sharpEdges[sharpEdges[i].Twin].Twin);
            }
        }
Пример #7
0
        public void TestSegmentDicretization()
        {
            List<Point> inputPoint = new List<Point>() { new Point(5, 5) };
            List<Segment> inputSegment = new List<Segment>();
            inputSegment.Add(new Segment(0, 0, 0, 10));
            inputSegment.Add(new Segment(0, 0, 10, 0));
            inputSegment.Add(new Segment(0, 10, 10, 10));
            inputSegment.Add(new Segment(10, 0, 10, 10));

            //Build the CLR voronoi
            VoronoiWrapper vw = new VoronoiWrapper();

            foreach (var p in inputPoint)
                vw.AddPoint(p.X, p.Y);

            foreach (var s in inputSegment)
                vw.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);

            vw.ConstructVoronoi();
            List<Tuple<int, int, bool, bool, List<int>, bool, short>> clrCells = vw.GetCells();

            //Build the C# Voronoi
            BoostVoronoi bv = new BoostVoronoi();
            foreach (var p in inputPoint)
                bv.AddPoint(p.X, p.Y);
            foreach (var s in inputSegment)
                bv.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);

            bv.Construct();
            List<Vertex> vertices = bv.Vertices;
            List<Edge> sharpEdges = bv.Edges;
            List<Cell> sharpCells = bv.Cells;

            int testEdgeIndex = 2;

            for (int i = 0; i < sharpEdges.Count; i++)
            {
                if (sharpCells[sharpEdges[sharpEdges[i].Twin].Cell].SourceCategory == CellSourceCatory.SinglePoint
                    &&
                    sharpCells[sharpEdges[i].Cell].Site == 1)
                    testEdgeIndex = i;

            }

            Edge testEdge = sharpEdges[testEdgeIndex];
            Vertex startVertex = vertices[testEdge.Start];
            Vertex endVertex = vertices[testEdge.End];
            List<Vertex> dvertices = bv.SampleCurvedEdge(testEdge, Distance.ComputeDistanceBetweenPoints(startVertex, endVertex) / 2);
            int lastDicretizedVertexIndex = dvertices.Count - 1;

            //Make sure that the end points are consistents
            Assert.AreEqual(dvertices[0].X, startVertex.X);
            Assert.AreEqual(dvertices[0].Y, startVertex.Y);

            Assert.AreEqual(dvertices[lastDicretizedVertexIndex].X, endVertex.X);
            Assert.AreEqual(dvertices[lastDicretizedVertexIndex].Y, endVertex.Y);

            Assert.AreEqual(dvertices[2].X, 2.5);
            Assert.AreEqual(dvertices[2].Y, 5);
        }
Пример #8
0
        public void TestPrimaryEdges()
        {
            List<Point> inputPoint = new List<Point>() { new Point(5, 5) };
            List<Segment> inputSegment = new List<Segment>();
            inputSegment.Add(new Segment(0, 0, 0, 10));
            inputSegment.Add(new Segment(0, 0, 10, 0));
            inputSegment.Add(new Segment(0, 10, 10, 10));
            inputSegment.Add(new Segment(10, 0, 10, 10));

            //Build the CLR voronoi
            VoronoiWrapper vw = new VoronoiWrapper();

            foreach (var p in inputPoint)
                vw.AddPoint(p.X, p.Y);

            foreach (var s in inputSegment)
                vw.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);

            vw.ConstructVoronoi();
            List<Tuple<int, int, bool, bool, List<int>, bool, short>> clrCells = vw.GetCells();

            //Build the C# Voronoi
            BoostVoronoi bv = new BoostVoronoi();
            foreach (var p in inputPoint)
                bv.AddPoint(p.X, p.Y);
            foreach (var s in inputSegment)
                bv.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y);

            bv.Construct();
            List<Vertex> vertices = bv.Vertices;
            List<Edge> sharpEdges = bv.Edges;

            int countPrimary = 0;
            int countSecondary = 0;
            int countFinite = 0;
            for (int i = 0; i < sharpEdges.Count; i++)
            {
                if (sharpEdges[i].IsPrimary)
                    countPrimary++;

                if (sharpEdges[i].IsFinite)
                    countFinite++;

                if (!sharpEdges[i].IsPrimary && sharpEdges[i].IsFinite)
                    countSecondary++;
            }

            //8 finites from the center of the square corner + 8 edges arount the center point.
            Assert.AreEqual(countFinite, 16);

            //Check the number of secondary edge. Because this input is a square with a point in the center, the expected count is 0.
            Assert.AreEqual(countSecondary, 0);

            Assert.AreEqual(countPrimary, countFinite - countSecondary);
        }
Пример #9
0
        public void TestTupleEdgeIndexes()
        {
            VoronoiWrapper vw = new VoronoiWrapper();
            vw.AddSegment(0, 0, 0, 10);
            vw.AddSegment(0, 10, 10, 10);
            vw.AddSegment(10, 10, 10, 0);
            vw.AddSegment(10, 0, 0, 0);
            vw.AddSegment(0, 0, 5, 5);
            vw.AddSegment(5, 5, 10, 10);
            vw.ConstructVoronoi();

            List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges();

            List<int> edgeIndexes = new List<int>();

            foreach (var e in edges)
            {
                edgeIndexes.Add(e.Item1);
            }

            edgeIndexes.Sort();
            int minIndex = edgeIndexes.Min();
            int maxIndex = edgeIndexes.Max();

            Assert.AreEqual(0, minIndex);
            Assert.AreEqual(edges.Count - 1, maxIndex);
        }
Пример #10
0
        public void TestVertexSequences()
        {
            VoronoiWrapper vw = new VoronoiWrapper();
            vw.AddSegment(0, 0, 0, 10);
            vw.AddSegment(0, 10, 10, 10);
            vw.AddSegment(10, 10, 10, 0);
            vw.AddSegment(10, 0, 0, 0);
            vw.AddSegment(0, 0, 5, 5);
            vw.AddSegment(5, 5, 10, 10);
            vw.ConstructVoronoi();

            List<Tuple<double, double>> vertices = vw.GetVertices();
            List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges();
            List<Tuple<int, int, bool, bool, List<int>, bool, short>> cells = vw.GetCells();

            foreach (var c in cells)
            {
                for (int i = 1; i < c.Item5.Count; i++)
                {
                    Assert.AreEqual(edges[c.Item5[i - 1]].Item3, edges[c.Item5[i]].Item2);
                }
            }
        }
Пример #11
0
        public void TestTupleVertices()
        {
            VoronoiWrapper vw = new VoronoiWrapper();
            vw.AddSegment(0, 0, 0, 10);
            vw.AddSegment(0, 10, 10, 10);
            vw.AddSegment(10, 10, 10, 0);
            vw.AddSegment(10, 0, 0, 0);
            vw.AddSegment(0, 0, 5, 5);
            vw.AddSegment(5, 5, 10, 10);
            vw.ConstructVoronoi();

            List<Tuple<double, double>> vertices = vw.GetVertices();
            Assert.AreEqual(6, vertices.Count);
        }
Пример #12
0
        public void TestTupleVertexIndexes()
        {
            VoronoiWrapper vw = new VoronoiWrapper();
            vw.AddSegment(0, 0, 0, 10);
            vw.AddSegment(0, 10, 10, 10);
            vw.AddSegment(10, 10, 10, 0);
            vw.AddSegment(10, 0, 0, 0);
            vw.AddSegment(0, 0, 5, 5);
            vw.AddSegment(5, 5, 10, 10);
            vw.ConstructVoronoi();

            List<Tuple<double, double>> vertices = vw.GetVertices();
            List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges();

            List<int> vertexIndexes = new List<int>();

            foreach (var e in edges)
            {
                if(!vertexIndexes.Exists(v=> v==e.Item2))
                    vertexIndexes.Add(e.Item2);

                if (!vertexIndexes.Exists(v => v == e.Item3))
                    vertexIndexes.Add(e.Item3);
            }

            vertexIndexes.Remove(-1);
            vertexIndexes.Sort();
            int minIndex = vertexIndexes.Min();
            int maxIndex = vertexIndexes.Max();

            Assert.AreEqual(0, minIndex);
            Assert.AreEqual(vertices.Count - 1, maxIndex);
        }
Пример #13
0
        public void TestTupleEdges()
        {
            VoronoiWrapper vw = new VoronoiWrapper();
            vw.AddSegment(0, 0, 0, 10);
            vw.AddSegment(0, 10, 10, 10);
            vw.AddSegment(10, 10, 10, 0);
            vw.AddSegment(10, 0, 0, 0);
            vw.AddSegment(0, 0, 5, 5);
            vw.AddSegment(5, 5, 10, 10);
            vw.ConstructVoronoi();

            List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges();
            int count_finite_edge = 0;
            foreach (var e in edges)
            {
                if (e.Item5.Item3)
                {
                    count_finite_edge++;
                }
            }

            Assert.AreEqual(16, count_finite_edge);
        }