Exemple #1
0
        private static void AddSeed(IMinHeap <KeyValuePair <float, Seed> > seeds, Seed seed, BaseScalarField priority = null, BaseScalarField separation = null)
        {
            Contract.Requires(seeds != null);

            var prio = priority.SafeSample(seed.Point)
                       + 1 / separation.SafeSample(seed.Point);

            seeds.Add(new KeyValuePair <float, Seed>(-prio, seed));
        }
        private void AssertHeapIsInOrder <T>(IMinHeap <T> heap, IComparer <T> comparer = null)
        {
            comparer = comparer ?? Comparer <T> .Default;

            var first = true;
            var min   = default(T);

            while (heap.Count > 0)
            {
                var i = heap.RemoveMin();
                if (!first)
                {
                    Assert.IsTrue(comparer.Compare(i, min) >= 0);
                }

                min   = i;
                first = false;
            }
        }
Exemple #3
0
        private Seed?RemoveSeed(IMinHeap <KeyValuePair <float, Seed> > seeds, BaseScalarField separation, float cosineSearchAngle, Func <Edge, bool> edgeFilter = null)
        {
            Contract.Requires(seeds != null);
            Contract.Requires(separation != null);

            while (seeds.Count > 0)
            {
                //Get the highest priority seed
                var s = seeds.RemoveMin().Value;

                //Check if it's valid
                var d = s.Field.Sample(s.Point);

                //Degenerate point?
                var l = d.Length();
                if (l < 0.001f)
                {
                    continue;
                }

                var sep = separation.Sample(s.Point);

                //Normalize direction
                d /= l;

                //Get edges near this point and check if there is a parallel edge
                if (FindEdges(s.Point, sep).Where(e => edgeFilter == null || edgeFilter(e)).Any(e => Math.Abs(Vector2.Dot(e.Direction, d)) > cosineSearchAngle))
                {
                    continue;
                }

                return(s);
            }

            //No valid seeds found
            return(null);
        }