Пример #1
0
        public override MtripletsFeature Extract(Bitmap image)
        {
            var minutiae  = MinutiaeExtractor.ExtractFeatures(ImageProvider.AdaptImage(image));
            var mtriplets = new List <MTriplet>();
            var triplets  = new Dictionary <int, int>();

            foreach (var triangle in Delaunay2D.Triangulate(minutiae))
            {
                var idxArr = new[]
                {
                    (short)triangle.A,
                    (short)triangle.B,
                    (short)triangle.C
                };
                var newMTriplet = new MTriplet(idxArr, minutiae);
                var newHash     = newMTriplet.GetHashCode();
                if (!triplets.ContainsKey(newHash))
                {
                    triplets.Add(newHash, 0);
                    mtriplets.Add(newMTriplet);
                }
            }

            mtriplets.TrimExcess();
            return(new MtripletsFeature(mtriplets, minutiae));
        }
        /// <summary>
        ///     Extract features of type <see cref="MtripletsFeature"/> from the specified minutiae.
        /// </summary>
        /// <param name="minutiae">
        ///     The list of <see cref="Minutia"/> to extract the features from.
        /// </param>
        /// <returns>
        ///     Features of type <see cref="MtripletsFeature"/> extracted from the specified minutiae.
        /// </returns>
        public MtripletsFeature ExtractFeatures(List <Minutia> minutiae)
        {
            List <MTriplet>       mtriplets = new List <MTriplet>();
            Dictionary <int, int> triplets  = new Dictionary <int, int>();

            foreach (var triangle in Delaunay2D.Triangulate(minutiae))
            {
                var idxArr = new short[]
                {
                    (short)triangle.A,
                    (short)triangle.B,
                    (short)triangle.C
                };
                MTriplet newMTriplet = new MTriplet(idxArr, minutiae);
                int      newHash     = newMTriplet.GetHashCode();
                if (!triplets.ContainsKey(newHash))
                {
                    triplets.Add(newHash, 0);
                    mtriplets.Add(newMTriplet);
                }
            }

            mtriplets.TrimExcess();
            return(new MtripletsFeature(mtriplets, minutiae));
        }
Пример #3
0
    public static Delaunay2D Triangulate(List <Vertex> vertices)
    {
        Delaunay2D delaunay = new Delaunay2D();

        delaunay.Vertices = new List <Vertex>(vertices);
        delaunay.Triangulate();

        return(delaunay);
    }
Пример #4
0
    void Triangulate()
    {
        List <Vertex> vertices = new List <Vertex>();

        foreach (var room in rooms)
        {
            vertices.Add(new Vertex <Room>((Vector2)room.bounds.position + ((Vector2)room.bounds.size) / 2, room));
        }

        delaunay = Delaunay2D.Triangulate(vertices);
    }
Пример #5
0
    private bool Triangulate()
    {
        bool          res      = false;
        List <Vertex> vertices = new List <Vertex>();

        foreach (var room in rooms)
        {
            vertices.Add(new Vertex <Room2D>((Vector2)room.bounds.position + ((Vector2)room.bounds.size) / 2, room));
        }

        delaunay = Delaunay2D.Triangulate(vertices);
        if (delaunay.Edges.Count > 0)
        {
            res = true;
        }
        return(res);
    }
Пример #6
0
    void OnPostRender()
    {
        if (!mat)
        {
            Debug.LogError("Please Assign a material on the inspector");
            return;
        }
        Delaunay2D      d         = new Delaunay2D();
        List <Triangle> triangles = d.Triangulate(points);

        GL.PushMatrix();
        mat.SetPass(0);
        GL.LoadOrtho();
        GL.Begin(GL.TRIANGLES);
        for (int i = 0, imax = triangles.Count; i < imax; i++)
        {
            GL.Vertex(triangles[i].V0);
            GL.Vertex(triangles[i].V1);
            GL.Vertex(triangles[i].V2);
        }
        GL.End();
        GL.PopMatrix();
    }
        public bool MakeHalls()
        {
            List <Vertex> vertices = new List <Vertex>();

            // add a vertex at the center of each room
            foreach (Rect room in _rooms)
            {
                vertices.Add(new Vertex <Rect>(new Vector2(room.Center.x, room.Center.y), room));
            }

            // Create a Delaunay triangulation of the rooms
            _delaunay = Delaunay2D.Triangulate(vertices);

            // Convert the Delaunay edges to Prim edges
            List <Prim.Edge> edges = new List <Prim.Edge>();

            foreach (Delaunay2D.Edge edge in _delaunay.Edges)
            {
                edges.Add(new Prim.Edge(edge.U, edge.V));
            }

            // Create a minimum spanning tree of the triangulation
            List <Prim.Edge> mst = Prim.MinimumSpanningTree(edges, edges[0].U);

            // Get the edges not part of the MST
            HashSet <Prim.Edge> selectedEdges  = new HashSet <Prim.Edge>(mst);
            HashSet <Prim.Edge> remainingEdges = new HashSet <Prim.Edge>(edges);

            remainingEdges.ExceptWith(selectedEdges);

            // Create some loops, since MSTs make for boring maps
            foreach (Prim.Edge edge in remainingEdges)
            {
                if (Rng.Int(100) < _writer.Options.ChanceOfExtraHallway)
                {
                    selectedEdges.Add(edge);
                }
            }

            // Drive a pathfinder to carve out the halls
            Motility motility = Motility.FourWayNeighbors | Motility.Unconstrained;

            foreach (Prim.Edge edge in selectedEdges)
            {
                Rect startRoom = (edge.U as Vertex <Rect>).Item;
                Rect endRoom   = (edge.V as Vertex <Rect>).Item;

                GridNode start = _writer.GetTile(new Vec2(startRoom.Center.x, startRoom.Center.y));
                GridNode goal  = _writer.GetTile(new Vec2(endRoom.Center.x, endRoom.Center.y));

                // Heuristic is Manhattan distance on a square grid
                IList <GridNode> path = _writer.Graph.FindPath <AStarSearchAlgorithm>(start, goal,
                                                                                      motility, (a, b) =>
                                                                                      Math.Abs((float)(a.Position.x - b.Position.x)) + Math.Abs((float)(a.Position.y - b.Position.y)));

                // Bail if the pathfinder failed to find a path (NOTE: if it does, it seems like it should be a problem)
                if (path == null)
                {
                    continue;
                }
                foreach (GridNode step in path)
                {
                    _writer.SetTile(step.Position, Tiles.Floor);
                    foreach (GridNode neighbor in step.Neighbors)
                    {
                        if ((_writer.GetTile(neighbor.Position)).Type == Tiles.Stone)
                        {
                            _writer.SetTile(neighbor.Position, Tiles.Wall);
                        }
                    }
                }
            }

            return(true);
        }
Пример #8
0
        /// <summary>
        ///     Extract features of type <see cref="PNFeatures"/> from the specified minutiae.
        /// </summary>
        /// <param name="minutiae">
        ///     The list of <see cref="Minutia"/> to extract the features from.
        /// </param>
        /// <returns>
        ///     Features of type <see cref="PNFeatures"/> extracted from the specified minutiae.
        /// </returns>
        public PNFeatures ExtractFeatures(List <Minutia> minutiae)
        {
            List <MtiaTriplet> result = new List <MtiaTriplet>();

            if (minutiae.Count > 3)
            {
                foreach (var triangle in Delaunay2D.Triangulate(minutiae))
                {
                    var idxArr = new short[]
                    {
                        (short)triangle.A,
                        (short)triangle.B,
                        (short)triangle.C
                    };
                    MtiaTriplet newMTriplet = new MtiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new short[]
                    {
                        (short)triangle.A,
                        (short)triangle.C,
                        (short)triangle.B
                    };
                    newMTriplet = new MtiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new short[]
                    {
                        (short)triangle.B,
                        (short)triangle.A,
                        (short)triangle.C
                    };
                    newMTriplet = new MtiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new short[]
                    {
                        (short)triangle.B,
                        (short)triangle.C,
                        (short)triangle.A
                    };
                    newMTriplet = new MtiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new short[]
                    {
                        (short)triangle.C,
                        (short)triangle.A,
                        (short)triangle.B
                    };
                    newMTriplet = new MtiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new short[]
                    {
                        (short)triangle.C,
                        (short)triangle.B,
                        (short)triangle.A
                    };
                    newMTriplet = new MtiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);
                }
            }
            result.TrimExcess();
            return(new PNFeatures(result, minutiae));
        }
Пример #9
0
        public override PartialeFeatures Extract(Bitmap image)
        {
            var minutiae = MinutiaeExtractor.ExtractFeatures(image);
            var result   = new List <MinutiaTriplet>();

            if (minutiae.Count > 3)
            {
                foreach (var triangle in Delaunay2D.Triangulate(minutiae))
                {
                    var idxArr = new[]
                    {
                        (short)triangle.A,
                        (short)triangle.B,
                        (short)triangle.C
                    };
                    var newMTriplet = new MinutiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new[]
                    {
                        (short)triangle.A,
                        (short)triangle.C,
                        (short)triangle.B
                    };
                    newMTriplet = new MinutiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new[]
                    {
                        (short)triangle.B,
                        (short)triangle.A,
                        (short)triangle.C
                    };
                    newMTriplet = new MinutiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new[]
                    {
                        (short)triangle.B,
                        (short)triangle.C,
                        (short)triangle.A
                    };
                    newMTriplet = new MinutiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new[]
                    {
                        (short)triangle.C,
                        (short)triangle.A,
                        (short)triangle.B
                    };
                    newMTriplet = new MinutiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);

                    idxArr = new[]
                    {
                        (short)triangle.C,
                        (short)triangle.B,
                        (short)triangle.A
                    };
                    newMTriplet = new MinutiaTriplet(idxArr, minutiae);
                    result.Add(newMTriplet);
                }
            }
            result.TrimExcess();
            return(new PartialeFeatures(result, minutiae));
        }