Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public BoostVoronoi()
 {
     InputPoints = new List<Point>();
     InputSegments = new List<Segment>();
     VoronoiWrapper = new VoronoiWrapper();
     ScaleFactor = 1;
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add a point to the list of input points
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        //public void AddPoint(int x, int y)
        //{
        //    InputPoints.Add(new Point(x * ScaleFactor, y * ScaleFactor));
        //}

        /// <summary>
        /// Add a point to the list of input points. The input points will be applied a scale factor
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void AddPoint(double x, double y)
        {
            Point p = new Point(Convert.ToInt32(x * ScaleFactor), Convert.ToInt32(y * ScaleFactor));

            InputPoints[InputPoints.Count] = p;
            VoronoiWrapper.AddPoint(p.X, p.Y);
        }
Ejemplo n.º 6
0
 public Edge GetEdge(long index)
 {
     if (index < -0 || index > this.CountEdges - 1)
     {
         throw new IndexOutOfRangeException();
     }
     return(new Edge(VoronoiWrapper.GetEdge(index)));
 }
Ejemplo n.º 7
0
 public Cell GetCell(long index)
 {
     if (index < -0 || index > this.CountCells - 1)
     {
         throw new IndexOutOfRangeException();
     }
     return(new Cell(VoronoiWrapper.GetCell(index)));
 }
Ejemplo n.º 8
0
        public Vertex GetVertex(long index)
        {
            if (index < -0 || index > this.CountVertices - 1)
            {
                throw new IndexOutOfRangeException();
            }

            return(new Vertex(VoronoiWrapper.GetVertex(index)));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public BoostVoronoi()
 {
     InputPoints    = new Dictionary <long, Point>();
     InputSegments  = new Dictionary <long, Segment>();
     VoronoiWrapper = new VoronoiWrapper();
     ScaleFactor    = 1;
     CountVertices  = -1;
     CountEdges     = -1;
     CountCells     = -1;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructor that allows to define a scale factor.
        /// </summary>
        /// <param name="scaleFactor"> A scale factor greater than zero. It will be used as a multiplier for input coordinates. Output coordinates will be divided by the scale factor automatically.</param>
        public BoostVoronoi(int scaleFactor)
        {
            InputPoints = new List<Point>();
            InputSegments = new List<Segment>();
            VoronoiWrapper = new VoronoiWrapper();

            if (scaleFactor <= 0)
                throw new InvalidScaleFactorException();

            ScaleFactor = scaleFactor;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Constructor that allows to define a scale factor.
        /// </summary>
        /// <param name="scaleFactor"> A scale factor greater than zero. It will be used as a multiplier for input coordinates. Output coordinates will be divided by the scale factor automatically.</param>
        public BoostVoronoi(int scaleFactor)
        {
            InputPoints    = new Dictionary <long, Point>();
            InputSegments  = new Dictionary <long, Segment>();
            VoronoiWrapper = new VoronoiWrapper();

            if (scaleFactor <= 0)
            {
                throw new InvalidScaleFactorException();
            }

            ScaleFactor = scaleFactor;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Calls the voronoi API in order to build the voronoi cells.
        /// </summary>
        public void Construct()
        {
            //Construct
            VoronoiWrapper.Construct();

            //Build Maps
            VoronoiWrapper.CreateVertexMap();
            VoronoiWrapper.CreateEdgeMap();
            VoronoiWrapper.CreateCellMap();

            //long maxEdgeSize = VoronoiWrapper.GetEdgeMapMaxSize();
            //long maxEdgeIndexSize = VoronoiWrapper.GetEdgeIndexMapMaxSize();

            this.CountVertices = VoronoiWrapper.CountVertices();
            this.CountEdges    = VoronoiWrapper.CountEdges();
            this.CountCells    = VoronoiWrapper.CountCells();
        }
Ejemplo n.º 13
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
                );
        }
Ejemplo n.º 14
0
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            //if (disposing)
            //{
            //    //Free managed object here
            //
            //}

            // Free any unmanaged objects here.
            VoronoiWrapper.Dispose();

            disposed = true;
        }
Ejemplo n.º 15
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);
            }
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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);
                }
            }
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Clears the list of the inserted geometries.
 /// </summary>
 public void Clear()
 {
     VoronoiWrapper.Clear();
 }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
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);
            }
        }
Ejemplo n.º 23
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);
            }
        }
Ejemplo n.º 24
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);
        }