Beispiel #1
0
        protected virtual void Initialize(FloodParameters parameters, int[,] markMatrix)
        {
            MarkMatrix = markMatrix;

            // deconstructing parameters
            NeighbourhoodType              = parameters.NeighbourhoodType;
            StartX                         = parameters.StartX;
            StartY                         = parameters.StartY;
            ProcessStartAsFirstNeighbour   = parameters.ProcessStartAsFirstNeighbour;
            Qualifier                      = parameters.Qualifier;
            NeighbourProcessor             = parameters.NeighbourProcessor;
            NeighbourStopCondition         = parameters.NeighbourStopCondition;
            SpreadingPositionVisitor       = parameters.SpreadingPositionVisitor;
            SpreadingPositionStopCondition = parameters.SpreadingPositionStopCondition;
            PositionsToVisit               = parameters.PositionsToVisitQueue;
            if (PositionsToVisit.Any())
            {
                throw new ArgumentException("Provided PositionsToVisitQueue was not empty at the beginning of flood spilling.", nameof(parameters));
            }
            FloodBounds boundsRestriction = parameters.BoundsRestriction
                                            ?? new FloodBounds(markMatrix.GetLength(0), markMatrix.GetLength(1));

            GuardBounds(boundsRestriction, StartX, StartY);
            OffsetX = -boundsRestriction.MinX;
            OffsetY = -boundsRestriction.MinY;
            MinX    = boundsRestriction.MinX;
            MinY    = boundsRestriction.MinY;
            MaxX    = boundsRestriction.MaxX;
            MaxY    = boundsRestriction.MaxY;

            InitializeMarkMatrix();
        }
Beispiel #2
0
        /// <summary>
        /// Spreads among positions that satisfy given conditions and marks them with growing numbers.<br/>
        /// Important definitions: <br/>
        /// VISITING A SPREADING POSITION means operating on a position just taken from the queue. <br/>
        /// PROCESSING A NEIGHBOUR means operating on a position reached while spreading from VISITED SPREADING POSITION. A neighbour may be added
        /// to the queue of positions to visit.<br/><br/>
        /// Neighbours by are with numbers having some relation to the number at spreading position - for example they can be bigger by 1
        /// than mark numbers of the position they are reached from.<br/>
        /// </summary>
        ///
        /// <remarks>Note that positions are marked before actually processing them, so if the algorithm stops with positions waiting in queue,
        /// they will be remain marked even though they haven't been processed yet.</remarks>
        /// <param name="markMatrix">A matrix that will be initialized with int.MaxValues and then used for storing positions marks. </param>
        /// <param name="parameters">Algorithm parameters.</param>
        /// <returns>True if execution has been stopped by meeting a stop condition. False if ran out of elements in queue.</returns>
        public virtual bool SpillFlood(FloodParameters parameters, int[,] markMatrix)
        {
            Initialize(parameters, markMatrix);

            bool stopConditionMet;

            try
            {
                stopConditionMet = RunFlood();
            }
            finally
            {
                // we make sure we won't prevent the matrix from being garbage collected
                MarkMatrix = null;
            }
            return(stopConditionMet);
        }