[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

NeighborCode Class Reference

Encapsulation of direction management for 4-neighborhood. More...

`#include <vigra/pixelneighborhood.hxx>`

## Public Types

enum | Direction { Error = -1 , East = 0 , North , West , South , DirectionCount , CausalFirst = North , CausalLast = West , AntiCausalFirst = South , AntiCausalLast = East , InitialDirection = East , OppositeDirPrefix = 1 , OppositeOffset = West }

## Static Public Member Functions

static Diff2D const & | bottom ()
static Direction | code (Diff2D const &diff)
static Diff2D const & | diff (Direction code)
static Diff2D const & | diff (int code)
static int | dX (Direction code)
static int | dX (int code)
static int | dY (Direction code)
static int | dY (int code)
static Diff2D const & | east ()
static bool | isDiagonal (Direction)
static Diff2D const & | left ()
static unsigned int | nearBorderDirectionCount (AtImageBorder b)
static Direction | nearBorderDirections (AtImageBorder b, int index)
static Diff2D const & | north ()
static Diff2D const & | relativeDiff (Direction fromCode, Direction toCode)
static Diff2D const & | relativeDiff (int fromCode, int toCode)
static Diff2D const & | right ()
static Diff2D const & | south ()
static Diff2D const & | top ()
static Diff2D const & | west ()

## Detailed Description

Encapsulation of direction management for 4-neighborhood.

This helper class allows the transformation between Freeman chain codes (East = 0, North = 1 etc.) and the corresponding Diff2D instances and back.

You can either use the chain codes by explicit qualification:

// the following three lines are equivalent
FourNeighborhood::NeighborCode::Direction d = FourNeighborhood::NeighborCode::East;
FourNeighborCode::Direction d = FourNeighborCode::East;
FourNeighborhood::Direction d = FourNeighborhood::East;
vigra::FourNeighborhood::NeighborCode::Direction
Direction
Definition pixelneighborhood.hxx:179
vigra::FourNeighborhood::NeighborCode::East
@ East
&#160;
Definition pixelneighborhood.hxx:181
vigra::FourNeighborhood::East
static const Direction East
Definition pixelneighborhood.hxx:324

or you can fix 4-neighborhood by importing the entire namespace in your function:

using namespace FourNeighborhood;
Direction d = East;

If you want to pass 4-neighborhood codes as a template parameter, use the class FourNeighborhood::NeighborCode.

#include <vigra/pixelneighborhood.hxx>
Namespace: vigra::FourNeighborhood

## Member Enumeration Documentation

## ◆ Direction

enum Direction

Freeman direction codes for the 4-neighborhood. `East = 0`, `North = 1` etc. `DirectionCount` may be used for portable loop termination conditions. `CausalFirst` and `CausalLast` are the first and last (inclusive) neighbors in the causal neighborhood, i.e. in the set of neighbors that have already been visited when the image is traversed in scan order. `AntiCausalFirst` and `AntiCausalLast` are the opposite.

Enumerator
Error |
East |
North |
West |
South |
DirectionCount |
CausalFirst |
CausalLast |
AntiCausalFirst |
AntiCausalLast |

## Member Function Documentation

## ◆ nearBorderDirectionCount()

static unsigned int nearBorderDirectionCount | ( | AtImageBorder | b | ) |

static

The number of valid neighbors if the current center is at the image border.

## ◆ nearBorderDirections()

static Direction nearBorderDirections | ( | AtImageBorder | b,
|  | int | index
| ) |  |

static

The valid direction codes when the center is at the image border. index must be in the range `0...nearBorderDirectionCount(b)-1`.

## ◆ diff() [1/2]

static Diff2D const & diff | ( | Direction | code | ) |

static

Transform direction code into corresponding Diff2D offset. (note: there is no bounds checking on the code you pass.)

## ◆ diff() [2/2]

static Diff2D const & diff | ( | int | code | ) |

static

Equivalent to `diff(static_cast<Direction>(code))`. (note: there is no bounds checking on the code you pass.)

## ◆ relativeDiff() [1/2]

static Diff2D const & relativeDiff | ( | Direction | fromCode,
|  | Direction | toCode
| ) |  |

static

Get the relative offset from one neighbor to the other. For example, `relativeDiff(East, West) == Diff2D(-2,0)`. (note: there is no bounds checking on the code you pass.)

## ◆ relativeDiff() [2/2]

static Diff2D const & relativeDiff | ( | int | fromCode,
|  | int | toCode
| ) |  |

static

Equivalent to relativeDiff(static_cast<Direction>(fromCode), static_cast<Direction>(toCode)). (note: there is no bounds checking on the code you pass.)

## ◆ dX() [1/2]

static int dX | ( | Direction | code | ) |

static

X-component of diff()

## ◆ dY() [1/2]

static int dY | ( | Direction | code | ) |

static

Y-component of diff()

## ◆ dX() [2/2]

static int dX | ( | int | code | ) |

static

X-component of diff()

## ◆ dY() [2/2]

static int dY | ( | int | code | ) |

static

Y-component of diff()

## ◆ code()

static Direction code | ( | Diff2D const & | diff | ) |

static

Transform Diff2D offset into corresponding direction code. The code `Direction::Error` will be returned if `diff` is not in the 4-neighborhood.

## ◆ isDiagonal()

static bool isDiagonal | ( | Direction |  | ) |

static

Check whether a code refers to a diagonal direction. Useful if you want to abstract the differences between 4- and 8-neighborhood. Always `false` for 4-neighborhood.

## ◆ right()

static Diff2D const & right | ( |  | ) |

static

Offset to the right neighbor

## ◆ top()

static Diff2D const & top | ( |  | ) |

static

Offset to the top neighbor

## ◆ left()

static Diff2D const & left | ( |  | ) |

static

Offset to the left neighbor

## ◆ bottom()

static Diff2D const & bottom | ( |  | ) |

static

Offset to the bottom neighbor

## ◆ east()

static Diff2D const & east | ( |  | ) |

static

Offset to the east neighbor

## ◆ north()

static Diff2D const & north | ( |  | ) |

static

Offset to the north neighbor

## ◆ west()

static Diff2D const & west | ( |  | ) |

static

Offset to the west neighbor

## ◆ south()

static Diff2D const & south | ( |  | ) |

static

Offset to the south neighbor

The documentation for this class was generated from the following file:

- vigra/pixelneighborhood.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.12.1