Q Slot Algorithm

Posted on by admin
Recursive flood fill with 4 directions

Megaminx Tutorial. The Megaminx has a total of 12 sides. In this tutorial, we choose white side as the bottom layer,gray side as the top layer. The other sides are divided into 2 halves—the upper half consisting of pink/light yellow/light blue/orange/light green, and the lower halfconsisting of blue/red/dark green/purple/yellow. Resets the target of a left navigation from the control to use the default navigation algorithm. Ownership will not be transferred. QSLOT void resetUp.

Flood fill, also called seed fill, is an algorithm that determines and alters the area connected to a given node in a multi-dimensional array with some matching attribute. It is used in the 'bucket' fill tool of paint programs to fill connected, similarly-colored areas with a different color, and in games such as Go and Minesweeper for determining which pieces are cleared. A variant called boundary fill uses the same algorithms but is defined as the area connected to a given node that does not have a particular attribute.[1]

Note: Flood filling is not suitable for drawing filled polygons, as it will miss some pixels in more acute corners. [2] Instead, see Even-odd rule and Nonzero-rule.

The Algorithm Parameters[edit]

Recursive flood fill with 8 directions

The traditional flood-fill algorithm takes three parameters: a start node, a target color, and a replacement color. The algorithm looks for all nodes in the array that are connected to the start node by a path of the target color and changes them to the replacement color. For a boundary-fill, in place of the target color, a border color would be supplied.

In order to generalize the algorithm in the common way, the following descriptions will instead have two routines available. [3] One called `Inside` which returns true for unfilled points that, by their color, would be inside the filled area, and one called `Set` which fills a pixel/node. Any node that has `Set` called on it must then no longer be `Inside`.

Depending on whether we consider nodes touching at the corners connected or not, we have two variations: eight-way and four-way respectively.

Stack-based recursive implementation (four-way)[edit]

The earliest-known, implicitly stack-based, recursive, four-way flood-fill implementation goes as follows:[4][5][6][7]

Though easy to understand, the implementation of the algorithm used above is impractical in languages and environments where stack space is severely constrained (e.g. Java applets).

Moving the recursion into a data structure[edit]

Four-way flood fill using a queue for storage
Four-way flood fill using a stack for storage

Q Slot Algorithm Software

Moving the recursion into a data structure (either a stack or a queue) prevents a stack overflow. It is similar to the simple recursive solution, except that instead of making recursive calls, it pushes the nodes onto a stack or queue for consumption, with the choice of data structure affecting the proliferation pattern:

Further potential optimizations[edit]

  • Check and set each node's pixel color before adding it to the stack/queue, reducing stack/queue size.
  • Use a loop for the east/west directions, queueing pixels above/below as you go. (Making it similar to the span filling algorithms, below.)
  • Interleave two or more copies of the code with extra stacks/queues, to allow OoO processors more opportunity to parallelise
  • Use multiple threads (ideally with slightly different visiting orders, so they don't stay in the same area) [6]

Advantages[edit]

  • Very simple algorithm - easy to make bug-free. [6]

Disadvantages[edit]

  • Uses a lot of memory, particularly when using a stack. [6]
  • Tests most filled pixels a total of four times.
  • Not suitable for pattern filling, as it requires pixel test results to change.
  • Access pattern is not cache-friendly, for the queueing variant.
  • Cannot easily optimize for multi-pixel words or bitplanes. [2]

Span Filling[edit]

Scanline fill (click to view animation)

It's possible to optimise things further by working primarily with spans. The first published complete example works on the following basic principle. [1] Starting with a seed point, you fill left and right and keep track of the edges. Then, you scan the same portion of the line above and the line below, searching for new seed-points to continue with. This algorithm is the most popular, for both citations and implementations[citation needed], despite testing most filled pixels three times in total. In pseudo-code form:

Over time, the following optimisations were realized:

  • When a new scan would be entirely within a grandparent span, it would certainly only find filled pixels, and so wouldn't need queueing. [1][6][3]
  • Further, when a new scan overlaps a grandparent span, only the overhangs (U-turns and W-turns) need to be scanned. [3]
  • It's possible to fill while scanning for seeds [6]

The final, combined-scan-and-fill span filler was then published in 1990, and proceeds as follows (though the version here corrects some bugs in the original): [8]

Advantages[edit]

  • 2x-8x faster than the pixel-recursive algorithm.
  • Easy to understand.
  • Access pattern is cache and bitplane-friendly. [6]
  • Can draw a horizontal line rather than setting individual pixels. [6]

Disadvantages[edit]

  • Still visits pixels it has already filled. (For the popular algorithm, 3 scans of most pixels. For the final one, only doing extra scans of pixels where there are holes in the filled area.) [3]
  • Not suitable for pattern filling, as it requires pixel test results to change.

Adding Pattern Filling Support[edit]

Two common ways to make the span and pixel-based algorithms support pattern filling are either to use a unique colour as a plain fill and then replace that with a pattern or to keep track (in a 2d boolean array or as regions) of which pixels have been visited, using it to indicate pixels are no longer fillable. Inside must then return false for such visited pixels. [3]

Graph-theoretic Filling[edit]

Some theorists applied explicit graph theory to the problem, treating spans of pixels, or aggregrates of such, as nodes and studying their connectivity. The first published graph theory algorithm worked similarly to the span filling, above, but had a way to detect when it would duplicate filling of spans. [9] Unfortunately, it had bugs that made it not complete some fills. [10] A corrected algorithm was later published with a similar basis in graph theory; however, it alters the image as it goes along, to temporarily block off potential loops, complicating the programmatic interface.[10] A later published algorithm depended on the boundary being distinct from everything else in the image and so isn't suitable for most uses; [11][3] it also requires an extra bit per pixel for bookkeeping. [3]

Advantages[edit]

  • Suitable for pattern filling, directly, as it never retests filled pixels. [9][10][11]
  • Double the speed of the original span algorithm, for uncomplicated fills. [3]
  • Access pattern is cache and bitplane-friendly. [6][3]

Disadvantages[edit]

  • Regularly, a span has to be compared to every other 'front' in the queue, which significantly slows down complicated fills. [3]
  • Switching back and forth between graph theoretic and pixel domains complicates understanding.
  • The code is fairly complicated, increasing the chances of bugs.
Q Slot Algorithm

Walk-based filling (Fixed-memory method)[edit]

A method exists that uses essentially no memory for four-connected regions by pretending to be a painter trying to paint the region without painting themselves into a corner. This is also a method for solving mazes. The four pixels making the primary boundary are examined to see what action should be taken. The painter could find themselves in one of several conditions:

  1. All four boundary pixels are filled.
  2. Three of the boundary pixels are filled.
  3. Two of the boundary pixels are filled.
  4. One boundary pixel is filled.
  5. Zero boundary pixels are filled.

Where a path or boundary is to be followed, the right-hand rule is used. The painter follows the region by placing their right-hand on the wall (the boundary of the region) and progressing around the edge of the region without removing their hand.

For case #1, the painter paints (fills) the pixel the painter is standing upon and stops the algorithm.

For case #2, a path leading out of the area exists. Paint the pixel the painter is standing upon and move in the direction of the open path.

For case #3, the two boundary pixels define a path which, if we painted the current pixel, may block us from ever getting back to the other side of the path. We need a 'mark' to define where we are and which direction we are heading to see if we ever get back to exactly the same pixel. If we already created such a 'mark', then we preserve our previous mark and move to the next pixel following the right-hand rule.

A mark is used for the first 2-pixel boundary that is encountered to remember where the passage started and in what direction the painter was moving. If the mark is encountered again and the painter is traveling in the same direction, then the painter knows that it is safe to paint the square with the mark and to continue in the same direction. This is because (through some unknown path) the pixels on the other side of the mark can be reached and painted in the future. The mark is removed for future use.

If the painter encounters the mark but is going in a different direction, then some sort of loop has occurred, which caused the painter to return to the mark. This loop must be eliminated. The mark is picked up, and the painter then proceeds in the direction indicated previously by the mark using a left-hand rule for the boundary (similar to the right-hand rule but using the painter's left hand). This continues until an intersection is found (with three or more open boundary pixels). Still using the left-hand rule the painter now searches for a simple passage (made by two boundary pixels). Upon finding this two-pixel boundary path, that pixel is painted. This breaks the loop and allows the algorithm to continue.

For case #4, we need to check the opposite 8-connected corners to see whether they are filled or not. If either or both are filled, then this creates a many-path intersection and cannot be filled. If both are empty, then the current pixel can be painted and the painter can move following the right-hand rule.

The algorithm trades time for memory. For simple shapes it is very efficient. However, if the shape is complex with many features, the algorithm spends a large amount of time tracing the edges of the region trying to ensure that all can be painted.

This algorithm was first available commercially in 1981 on a Vicom Image Processing system manufactured by Vicom Systems, Inc.[citation needed] A walking algorithm was published in 1994.[12] The classic recursive flood fill algorithm was available on the Vicom system as well.

Pseudocode[edit]

This is a pseudocode implementation of an optimal fixed-memory flood-fill algorithm written in structured English:

The variables:cur, mark, and mark2 each hold either pixel coordinates or a null value

cur-dir, mark-dir, and mark2-dir each hold a direction (left, right, up, or down)backtrack and findloop each hold boolean valuescount is an integer

The algorithm:

(NOTE: All directions (front, back, left, right) are relative to cur-dir)

Advantages[edit]

  • Constant memory usage.

Disadvantages[edit]

  • Access pattern is not cache or bitplane-friendly.
  • Can spend a lot of time walking around loops before closing them.

Vector implementations[edit]

Version 0.46 of Inkscape includes a bucket fill tool, giving output similar to ordinary bitmap operations and indeed using one: the canvas is rendered, a flood fill operation is performed on the selected area and the result is then traced back to a path. It uses the concept of a boundary condition.

See also[edit]

External links[edit]

  • Sample implementations for recursive and non-recursive, classic and scanline flood fill, by Lode Vandevenne.
  • Flash flood fill implementation, by Emanuele Feronato.
  • QuickFill: An efficient flood fill algorithm., by John R. Shaw.
  • FloodSpill: an open-source flood filling algorithm for C#, by Paweł Ślusarczyk

References[edit]

  1. ^ abcSmith, Alvy Ray (1979). Tint Fill. SIGGRAPH '79: Proceedings of the 6th annual conference on Computer graphics and interactive techniques. pp. 276–283. doi:10.1145/800249.807456.
  2. ^ abAckland, Bryan D; Weste, Neil H (1981). The edge flag algorithm — A fill method for raster scan displays. IEEE Transactions on Computers (Volume: C-30, Issue: 1). pp. 41–48. doi:10.1109/TC.1981.6312155.
  3. ^ abcdefghijFishkin, Kenneth P; Barsky, Brian A (1985). An Analysis and Algorithm for Filling Propagation. Computer-Generated Images: The State of the Art Proceedings of Graphics Interface ’85. pp. 56–76. doi:10.1007/978-4-431-68033-8_6.
  4. ^Newman, William M; Sproull, Robert Fletcher (1979). Principles of Interactive Computer Graphics (2nd ed.). McGraw-Hill. p. 253. ISBN978-0-07-046338-7.
  5. ^Pavlidis, Theo (1982). Algorithms for Graphics and Image Processing. Springer-Verlag. p. 181. ISBN978-3-642-93210-6.
  6. ^ abcdefghiLevoy, Marc (1982). Area Flooding Algorithms. SIGGRAPH 1981 Two-Dimensional Computer Animation course notes.
  7. ^Foley, J D; van Dam, A; Feiner, S K; Hughes, S K (1990). Computer Graphics: Principles and Practice (2nd ed.). Addison–Wesley. pp. 979–982. ISBN978-0-201-84840-3.
  8. ^Heckbert, Paul S (1990). 'IV.10: A Seed Fill Algorithm'. In Glassner, Andrew S (ed.). Graphics Gems. Academic Press. pp. 275–277. ISBN0122861663.
  9. ^ abLieberman, Henry (1978). How to Color in a Coloring Book. SIGGRAPH '78: Proceedings of the 5th annual conference on Computer graphics and interactive techniques. pp. 111–116. doi:10.1145/800248.807380.
  10. ^ abcShani, Uri (1980). Filling regions in binary raster images: A graph-theoretic approach. SIGGRAPH '80: Proceedings of the 7th annual conference on Computer graphics and interactive techniques. pp. 321–327. doi:10.1145/800250.807511.
  11. ^ abPavlidis, Theo (1981). Contour Filling in Raster Graphics. SIGGRAPH '81: Proceedings of the 8th annual conference on Computer graphics and interactive techniques. pp. 29–36. doi:10.1145/800224.806786.
  12. ^Henrich, Dominik (1994). Space-efficient region filling in raster graphics. The Visual Computer. pp. 205–215. doi:10.1007/BF01901287.
Retrieved from 'https://en.wikipedia.org/w/index.php?title=Flood_fill&oldid=1004118530'
Results 1 - 10 of708

Topology Control of Multihop WirelessNetworksusing Transmit Power Adjustment

'... We consider the problem of adjusting the transmit powers of nodes in a multihop wireless network (also called an ad hoc network) to create a desired topology. We formulate it as a constrained optimization problem with two constraints- connectivity and biconnectivity, and one optimization objective- ...'
SlotAbstract - Cited by 688 (3 self) - Add to MetaCart
- maximum power used. We present two centralized algorithms for use in static networks, and prove their optimality. For mobile networks, we present two distributed heuristics that adaptively adjust node transmit powers in response to topological changes and attempt to maintain a connected topologyusing

Adaptive clustering for mobile wirelessnetworks

- IEEE Journal on Selected Areas in Communications, 1997
'... This paper describes a self-organizing, multihop, mobile radio network, which relies on a code division access scheme for multimedia support. In the proposed network architecture, nodes are organized into nonoverlapping clusters. The clusters are independently controlled and are dynamically reconfig ...'
Abstract - Cited by 561 (11 self) - Add to MetaCart
reconfigured as nodes move. This network architecture has three main advantages. First, it provides spatial reuse of the bandwidth due to node clustering. Secondly, bandwidth can be shared or reserved in a controlled fashion in each cluster. Finally, the cluster algorithm is robust in the face of topological

Robust Positioning Algorithms for Distributed Ad-Hoc WirelessSensorNetworks

'... A distributed algorithm for determining the positions of nodes in an ad-hoc, wireless sensor network is explained in detail. Details regarding the implementation of such an algorithm are also discussed. Experimentation is performed on networks containing 400 nodes randomly placed within a square are ...'
Abstract - Cited by 383 (9 self) - Add to MetaCart
Adistributedalgorithm for determining the positions of nodes in an ad-hoc, wirelesssensornetwork is explained in detail. Details regarding the implementation of such an algorithm are also discussed. Experimentation is performed on networks containing 400 nodes randomly placed within a square

ASCENT: Adaptive self-configuring sensornetworkstopologies

'... Advances in microsensor and radio technology will enable small but smart sensors to be deployed for a wide range of environmental monitoring applications. The low per-node cost will allow these wireless networks of sensors and actuators to be densely distributed. The nodes in these dense networks w ...'
Abstract - Cited by 449 (15 self) - Add to MetaCart

Q Slot Algorithm Game

Advances in microsensor and radio technology will enable small but smart sensors to be deployed for a wide range of environmental monitoring applications. The low per-node cost will allow these wirelessnetworks of sensors and actuators to be densely distributed. The nodes in these dense networks

Randomized Gossip Algorithms

'... Motivated by applications to sensor, peer-to-peer, and ad hoc networks, we study distributed algorithms, also known as gossip algorithms, for exchanging information and for computing in an arbitrarily connected network of nodes. The topology of such networks changes continuously as new nodes join a ...'
Abstract - Cited by 532 (5 self) - Add to MetaCart
Motivated by applications to sensor, peer-to-peer, and ad hoc networks, we study distributedalgorithms, also known as gossip algorithms, for exchanging information and for computing in an arbitrarily connected network of nodes. The topology of such networks changes continuously as new nodes join

RobustTopologyusingReconfigurableRadios in WirelessSensorNetworks

'... Abstract—Using SDR technology, the distributed al-gorithm RMA is used by sensor nodes to reconfigure their radio according to some predefined radio-modes, such that the resulting topology is connected to the sink. This mechanism reduces interference and increases data delivery rate. In this paper we ...'
Abstract - Add to MetaCart
Abstract—Using SDR technology, the distributedal-gorithm RMA is used by sensor nodes to reconfigure their radio according to some predefined radio-modes, such that the resulting topology is connected to the sink. This mechanism reduces interference and increases data delivery rate. In this paper

The flooding time synchronization protocol

'... Wireless sensor network applications, similarly to other distributed systems, often require a scalable time synchronization service enabling data consistency and coordination. This paper introduces the robust Flooding Time Synchronization Protocol (FTSP), especially tailored for applications requir ...'
Abstract - Cited by 469 (16 self) - Add to MetaCartAlgorithm
Wirelesssensornetwork applications, similarly to other distributed systems, often require a scalable time synchronization service enabling data consistency and coordination. This paper introduces the robust Flooding Time Synchronization Protocol (FTSP), especially tailored for applications

A simple cooperative diversity method based on network path selection

'... Cooperative diversity has been recently proposed as a way to form virtual antenna arrays that provide dramatic gains in slow fading wireless environments. However, most of the proposed solutions require distributed space–time coding algorithms, the careful design of which is left for future investi ...'

Q Slot Algorithm Games

Abstract - Cited by 452 (14 self) - Add to MetaCart
Cooperative diversity has been recently proposed as a way to form virtual antenna arrays that provide dramatic gains in slow fading wireless environments. However, most of the proposed solutions require distributed space–time coding algorithms, the careful design of which is left for future

Z-MAC: a Hybrid MAC for WirelessSensorNetworks

'... Z-MAC is a hybrid MAC protocol for wireless sensor networks. It combines the strengths of TDMA and CSMA while offsetting their weaknesses. Nodes are assigned time slots using a distributed implementation of RAND. Unlike TDMA where a node is allowed to transmit only during its own assigned slots, a n ...'
Abstract - Cited by 296 (7 self) - Add to MetaCart
Z-MAC is a hybrid MAC protocol for wirelesssensornetworks. It combines the strengths of TDMA and CSMA while offsetting their weaknesses. Nodes are assigned time slots usingadistributed implementation of RAND. Unlike TDMA where a node is allowed to transmit only during its own assigned slots, a

Q Slot Algorithm Definition

Analysis of a cone-based distributedtopology control algorithm for wireless multi-hop networks

- In ACM Symposium on Principle of Distributed Computing (PODC, 2001
'... bahl~microsoft, corn ymwang~microsoft, corn rogerwa~microsoft, corn The topology of a wireless multi-hop network can be con-trolled by varying the transmission power at each node. In this paper, we give a detailed analysis of a cone-based dis-tributed topology control algorithm. This algorithm, intr ...'
Abstract - Cited by 174 (14 self) - Add to MetaCart
bahl~microsoft, corn ymwang~microsoft, corn rogerwa~microsoft, corn The topology of awireless multi-hop network can be con-trolled by varying the transmission power at each node. In this paper, we give a detailed analysis of a cone-based dis-tributedtopology control algorithm. This algorithm
Results 1 - 10 of708