36 #ifndef VIGRA_PIXELNEIGHBORHOOD_HXX
37 #define VIGRA_PIXELNEIGHBORHOOD_HXX
39 #include "utilities.hxx"
132 namespace FourNeighborhood
191 InitialDirection =
East,
192 OppositeDirPrefix = 1,
193 OppositeOffset =
West
196 static unsigned int directionBit(
Direction d)
198 static unsigned int b[] = {1 <<
East,
209 static unsigned int c[] = { 4, 3, 3, 0, 3, 2, 2, 0, 3, 2, 2};
263 return d[fromCode][toCode];
271 return relativeDiff(static_cast<Direction>(fromCode), static_cast<Direction>(toCode));
305 return (diff.
y == 0) ?
311 return (diff.
y == 0) ?
365 namespace EightNeighborhood
427 InitialDirection =
East,
428 OppositeDirPrefix = 1,
429 OppositeOffset =
West
432 static unsigned int directionBit(
Direction d)
434 static unsigned int b[] = {1 <<
East,
449 static unsigned int c[] = { 8, 5, 5, 0, 5, 3, 3, 0, 5, 3, 3};
516 return d[fromCode][toCode];
524 return relativeDiff(static_cast<Direction>(fromCode), static_cast<Direction>(toCode));
668 template<
class NEIGHBORCODE>
670 :
public NEIGHBORCODE
673 typedef NEIGHBORCODE NeighborCode;
717 direction_ =
static_cast<Direction>((direction_+1) % NEIGHBORCODE::DirectionCount);
724 direction_ =
static_cast<Direction>((direction_ + NEIGHBORCODE::DirectionCount-1) % NEIGHBORCODE::DirectionCount);
747 direction_ =
static_cast<Direction>((direction_ + d) % NEIGHBORCODE::DirectionCount);
749 direction_ =
static_cast<Direction>(direction_ + NEIGHBORCODE::DirectionCount);
756 direction_ =
static_cast<Direction>((direction_ - d) % NEIGHBORCODE::DirectionCount);
758 direction_ =
static_cast<Direction>(direction_ + NEIGHBORCODE::DirectionCount);
780 direction_ =
static_cast<Direction>((direction_ + NEIGHBORCODE::South) % NEIGHBORCODE::DirectionCount);
790 direction_ =
static_cast<Direction>((direction_ + NEIGHBORCODE::North) % NEIGHBORCODE::DirectionCount);
815 return direction_ == o.direction_;
821 return direction_ != o.direction_;
827 return direction_ - o.direction_;
852 return NEIGHBORCODE::diff(direction_);
859 return NEIGHBORCODE::diff(dir);
867 Direction toDir =
static_cast<Direction>((direction_ + offset) % NEIGHBORCODE::DirectionCount);
869 toDir =
static_cast<Direction>(toDir + NEIGHBORCODE::DirectionCount);
870 return NEIGHBORCODE::relativeDiff(direction_, toDir);
876 return NEIGHBORCODE::dX(direction_);
882 return NEIGHBORCODE::dY(direction_);
889 return NEIGHBORCODE::isDiagonal(direction_);
903 return NEIGHBORCODE::directionBit(direction_);
910 return static_cast<Direction>((NEIGHBORCODE::OppositeDirPrefix*direction_ + NEIGHBORCODE::OppositeOffset) % NEIGHBORCODE::DirectionCount);
917 return NEIGHBORCODE::directionBit(
opposite());
924 int result = (direction_ + offset) % NEIGHBORCODE::DirectionCount;
926 result += NEIGHBORCODE::DirectionCount;
993 template <
class IMAGEITERATOR,
class NEIGHBORCODE>
1041 Direction d = NEIGHBOROFFSETCIRCULATOR::InitialDirection)
1042 : IMAGEITERATOR(
center), neighborCode_(d)
1114 (oldDirection, neighborCode_.
direction()));
1127 (oldDirection, neighborCode_.
direction()));
1140 (oldDirection, neighborCode_.
direction()));
1151 (oldDirection, neighborCode_.
direction()));
1178 return neighborCode_ == rhs.neighborCode_ &&
1185 return neighborCode_ != rhs.neighborCode_ ||
1192 return neighborCode_ - rhs.neighborCode_;
1198 return IMAGEITERATOR::operator*();
1204 return IMAGEITERATOR::operator[](neighborCode_.
relativeDiff(d));
1210 return IMAGEITERATOR::operator->();
1240 return neighborCode_.
diff();
1250 NEIGHBOROFFSETCIRCULATOR neighborCode_;
1301 template <
class IMAGEITERATOR,
class NEIGHBORCODE>
1349 :
BaseType(
center, NEIGHBORCODE::nearBorderDirections(atBorder, 0)),
1350 whichBorder_(atBorder),
1351 count_(NEIGHBORCODE::nearBorderDirectionCount(atBorder)),
1386 current_ =
static_cast<Direction>((current_ + count_ + d) % count_);
1387 BaseType::turnTo(NEIGHBORCODE::nearBorderDirections(whichBorder_, current_));
1416 return current_ == rhs.current_;
1422 return current_ != rhs.current_;
1428 return (current_ - rhs.current_) % count_;
1468 typename NeighborCode::difference_type
const &
diff()
const
1481 signed char count_, current_;
static const Direction DirectionCount
Definition: pixelneighborhood.hxx:629
Definition: pixelneighborhood.hxx:424
RestrictedNeighborhoodCirculator(IMAGEITERATOR const ¢er=IMAGEITERATOR(), AtImageBorder atBorder=NotAtBorder)
Definition: pixelneighborhood.hxx:1347
static Diff2D const & southEast()
Definition: pixelneighborhood.hxx:614
base_type center() const
Definition: pixelneighborhood.hxx:1220
bool isDiagonal() const
Definition: pixelneighborhood.hxx:1244
Diff2D const & north()
Definition: pixelneighborhood.hxx:348
static Diff2D const & west()
Definition: pixelneighborhood.hxx:332
Definition: pixelneighborhood.hxx:186
NEIGHBORCODE::Direction Direction
Definition: pixelneighborhood.hxx:1014
NeighborhoodCirculator & operator-=(difference_type d)
Definition: pixelneighborhood.hxx:1084
NeighborOffsetCirculator & turnRound()
Definition: pixelneighborhood.hxx:798
RestrictedNeighborhoodCirculator & operator-=(difference_type d)
Definition: pixelneighborhood.hxx:1392
Definition: pixelneighborhood.hxx:420
static Diff2D const & top()
Definition: pixelneighborhood.hxx:600
bool operator!=(NeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1183
reference diff() const
Definition: pixelneighborhood.hxx:850
Circulator that walks around a given location in a given image, using a restricted neighborhood...
Definition: pixelneighborhood.hxx:1302
static Diff2D const & north()
Definition: pixelneighborhood.hxx:331
IMAGEITERATOR base_type
Definition: pixelneighborhood.hxx:1002
static int dX(Direction code)
Definition: pixelneighborhood.hxx:275
Definition: pixelneighborhood.hxx:414
NeighborhoodCirculator operator--(int)
Definition: pixelneighborhood.hxx:1068
int y
Definition: diff2d.hxx:392
Direction
Definition: pixelneighborhood.hxx:411
BaseType::index_reference index_reference
Definition: pixelneighborhood.hxx:1330
Definition: pixelneighborhood.hxx:416
static Diff2D const & top()
Definition: pixelneighborhood.hxx:326
static const Direction SouthWest
Definition: pixelneighborhood.hxx:626
Definition: pixelneighborhood.hxx:188
RestrictedNeighborhoodCirculator operator--(int)
Definition: pixelneighborhood.hxx:1376
RestrictedNeighborhoodCirculator & operator--()
Definition: pixelneighborhood.hxx:1370
bool isDiagonal() const
Definition: pixelneighborhood.hxx:1474
NEIGHBORCODE NeighborCode
Definition: pixelneighborhood.hxx:1006
static Diff2D const & diff(Direction code)
Definition: pixelneighborhood.hxx:477
static bool isDiagonal(Direction)
Definition: pixelneighborhood.hxx:323
static const Direction Error
Definition: pixelneighborhood.hxx:340
NeighborOffsetCirculator & turnLeft()
Definition: pixelneighborhood.hxx:788
NeighborOffsetCirculator< FourNeighborCode > FourNeighborOffsetCirculator
Definition: pixelneighborhood.hxx:937
difference_type operator-(RestrictedNeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1426
Definition: pixelneighborhood.hxx:189
NeighborOffsetCirculator(Direction dir=NEIGHBORCODE::InitialDirection)
Definition: pixelneighborhood.hxx:709
bool operator==(RestrictedNeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1414
static unsigned int nearBorderDirectionCount(AtImageBorder b)
Definition: pixelneighborhood.hxx:207
AtImageBorder
Encode whether a point is near the image border.
Definition: pixelneighborhood.hxx:68
Definition: pixelneighborhood.hxx:75
int x
Definition: diff2d.hxx:385
NeighborOffsetCirculator & operator+=(difference_type d)
Definition: pixelneighborhood.hxx:745
static Diff2D const & northWest()
Definition: pixelneighborhood.hxx:610
RestrictedNeighborhoodCirculator operator-(difference_type d) const
Definition: pixelneighborhood.hxx:1406
static Diff2D const & topRight()
Definition: pixelneighborhood.hxx:599
BaseType::pointer pointer
Definition: pixelneighborhood.hxx:1334
pointer operator->() const
Definition: pixelneighborhood.hxx:1208
unsigned int directionBit() const
Definition: pixelneighborhood.hxx:1232
Definition: pixelneighborhood.hxx:421
NEIGHBORCODE::Direction Direction
Definition: pixelneighborhood.hxx:677
Two dimensional difference vector.
Definition: diff2d.hxx:185
IMAGEITERATOR::pointer pointer
Definition: pixelneighborhood.hxx:1027
AtImageBorder isAtImageBorder(int x, int y, int width, int height)
Find out whether a point is at the image border.
Definition: pixelneighborhood.hxx:111
unsigned int directionBit() const
Definition: pixelneighborhood.hxx:1462
static Diff2D const & left()
Definition: pixelneighborhood.hxx:327
NeighborOffsetCirculator operator++(int)
Definition: pixelneighborhood.hxx:729
NeighborOffsetCirculator< EightNeighborCode > EightNeighborOffsetCirculator
Definition: pixelneighborhood.hxx:933
static unsigned int nearBorderDirectionCount(AtImageBorder b)
Definition: pixelneighborhood.hxx:447
NeighborOffsetCirculator operator--(int)
Definition: pixelneighborhood.hxx:737
Diff2D const & west()
Definition: pixelneighborhood.hxx:349
Definition: pixelneighborhood.hxx:185
static const Direction South
Definition: pixelneighborhood.hxx:344
pointer operator->() const
Definition: pixelneighborhood.hxx:1438
BaseType::reference reference
Definition: pixelneighborhood.hxx:1326
int difference_type
Definition: pixelneighborhood.hxx:697
Diff2D const & east()
Definition: pixelneighborhood.hxx:347
NeighborhoodCirculator & operator++()
Definition: pixelneighborhood.hxx:1048
index_reference operator[](difference_type d) const
Definition: pixelneighborhood.hxx:837
unsigned int directionBit() const
Definition: pixelneighborhood.hxx:901
NeighborCode::Direction Direction
Definition: pixelneighborhood.hxx:338
static Direction nearBorderDirections(AtImageBorder b, int index)
Definition: pixelneighborhood.hxx:456
Encapsulation of direction management for 4-neighborhood.
Definition: pixelneighborhood.hxx:165
Definition: pixelneighborhood.hxx:73
static const Direction South
Definition: pixelneighborhood.hxx:627
IMAGEITERATOR::reference reference
Definition: pixelneighborhood.hxx:1018
Definition: pixelneighborhood.hxx:422
NeighborOffsetCirculator operator+(difference_type d) const
Definition: pixelneighborhood.hxx:763
Definition: pixelneighborhood.hxx:425
static Diff2D const & south()
Definition: pixelneighborhood.hxx:613
static int dY(int code)
Definition: pixelneighborhood.hxx:534
NeighborhoodCirculator & moveCenterToNeighbor()
Definition: pixelneighborhood.hxx:1158
static Diff2D const & left()
Definition: pixelneighborhood.hxx:602
NeighborhoodCirculator & turnRound()
Definition: pixelneighborhood.hxx:1135
bool operator!=(NeighborOffsetCirculator const &o) const
Definition: pixelneighborhood.hxx:819
static Diff2D const & east()
Definition: pixelneighborhood.hxx:607
NeighborhoodCirculator & turnTo(Direction d)
Definition: pixelneighborhood.hxx:1146
NeighborhoodCirculator & operator+=(difference_type d)
Definition: pixelneighborhood.hxx:1076
static Diff2D const & bottomLeft()
Definition: pixelneighborhood.hxx:603
NeighborOffsetCirculator & operator-=(difference_type d)
Definition: pixelneighborhood.hxx:754
Direction
Definition: pixelneighborhood.hxx:179
NEIGHBOROFFSETCIRCULATOR::difference_type difference_type
Definition: pixelneighborhood.hxx:1031
static Diff2D const & diff(Direction code)
Definition: pixelneighborhood.hxx:237
Circulator that walks around a given location.
Definition: pixelneighborhood.hxx:669
Definition: pixelneighborhood.hxx:419
NEIGHBORCODE::difference_type value_type
Definition: pixelneighborhood.hxx:681
RestrictedNeighborhoodCirculator operator++(int)
Definition: pixelneighborhood.hxx:1362
FFTWComplex< R > & operator+=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
add-assignment
Definition: fftw3.hxx:859
static const Direction NorthWest
Definition: pixelneighborhood.hxx:624
static Diff2D const & diff(int code)
Definition: pixelneighborhood.hxx:248
Diff2D const & northWest()
Definition: pixelneighborhood.hxx:634
base_type const & base() const
Definition: pixelneighborhood.hxx:1444
static int dY(Direction code)
Definition: pixelneighborhood.hxx:277
Direction direction(difference_type offset) const
Definition: pixelneighborhood.hxx:922
value_type const * pointer
Definition: pixelneighborhood.hxx:693
static Direction nearBorderDirections(AtImageBorder b, int index)
Definition: pixelneighborhood.hxx:216
NEIGHBORCODE NeighborCode
Definition: pixelneighborhood.hxx:1314
NeighborCode::Direction Direction
Definition: pixelneighborhood.hxx:619
NeighborhoodCirculator(IMAGEITERATOR const ¢er=IMAGEITERATOR(), Direction d=NEIGHBOROFFSETCIRCULATOR::InitialDirection)
Definition: pixelneighborhood.hxx:1040
Definition: pixelneighborhood.hxx:180
Definition: pixelneighborhood.hxx:184
reference operator*() const
Definition: pixelneighborhood.hxx:1432
static Diff2D const & diff(int code)
Definition: pixelneighborhood.hxx:489
NeighborhoodCirculator & turnLeft()
Definition: pixelneighborhood.hxx:1122
bool operator!=(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
not equal
Definition: fftw3.hxx:841
Definition: pixelneighborhood.hxx:423
static const Direction NorthEast
Definition: pixelneighborhood.hxx:622
static int dX(Direction code)
Definition: pixelneighborhood.hxx:528
static Diff2D const & bottomRight()
Definition: pixelneighborhood.hxx:605
static Diff2D const & relativeDiff(int fromCode, int toCode)
Definition: pixelneighborhood.hxx:269
bool operator==(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
equal
Definition: fftw3.hxx:825
BaseType::difference_type difference_type
Definition: pixelneighborhood.hxx:1338
static Direction code(Diff2D const &diff)
Definition: pixelneighborhood.hxx:287
static const Direction West
Definition: pixelneighborhood.hxx:625
RestrictedNeighborhoodCirculator operator+(difference_type d) const
Definition: pixelneighborhood.hxx:1398
Circulator that walks around a given location in a given image.
Definition: pixelneighborhood.hxx:994
int dY() const
Definition: pixelneighborhood.hxx:880
static Diff2D const & northEast()
Definition: pixelneighborhood.hxx:608
NeighborOffsetCirculator & operator++()
Definition: pixelneighborhood.hxx:715
difference_type operator-(NeighborOffsetCirculator const &o) const
Definition: pixelneighborhood.hxx:825
NeighborhoodCirculator & operator--()
Definition: pixelneighborhood.hxx:1062
index_reference operator[](difference_type d) const
Definition: pixelneighborhood.hxx:1202
static const Direction SouthEast
Definition: pixelneighborhood.hxx:628
static const Direction North
Definition: pixelneighborhood.hxx:623
Direction opposite() const
Definition: pixelneighborhood.hxx:908
NeighborhoodCirculator & swapCenterNeighbor()
Definition: pixelneighborhood.hxx:1168
difference_type operator-(NeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1190
bool isDiagonal() const
Definition: pixelneighborhood.hxx:887
static Diff2D const & relativeDiff(Direction fromCode, Direction toCode)
Definition: pixelneighborhood.hxx:254
NeighborhoodCirculator operator++(int)
Definition: pixelneighborhood.hxx:1054
NeighborhoodCirculator operator+(difference_type d) const
Definition: pixelneighborhood.hxx:1090
static Diff2D const & east()
Definition: pixelneighborhood.hxx:330
static Direction code(Diff2D const &diff)
Definition: pixelneighborhood.hxx:545
static int dX(int code)
Definition: pixelneighborhood.hxx:532
BaseType::iterator_category iterator_category
Definition: pixelneighborhood.hxx:1342
Diff2D const & south()
Definition: pixelneighborhood.hxx:350
static Diff2D const & bottom()
Definition: pixelneighborhood.hxx:604
Direction direction() const
Definition: pixelneighborhood.hxx:1456
BaseType::Direction Direction
Definition: pixelneighborhood.hxx:1322
static reference diff(Direction dir)
Definition: pixelneighborhood.hxx:857
Direction direction() const
Definition: pixelneighborhood.hxx:1226
static int dX(int code)
Definition: pixelneighborhood.hxx:279
bool operator!=(RestrictedNeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1420
pointer operator->() const
Definition: pixelneighborhood.hxx:843
static const Direction East
Definition: pixelneighborhood.hxx:341
NeighborOffsetCirculator & operator--()
Definition: pixelneighborhood.hxx:722
Diff2D const & south()
Definition: pixelneighborhood.hxx:637
static const Direction DirectionCount
Definition: pixelneighborhood.hxx:345
static const Direction North
Definition: pixelneighborhood.hxx:342
RestrictedNeighborhoodCirculator & operator++()
Definition: pixelneighborhood.hxx:1356
Diff2D const & southEast()
Definition: pixelneighborhood.hxx:638
NeighborCode::difference_type const & diff() const
Definition: pixelneighborhood.hxx:1468
Direction direction() const
Definition: pixelneighborhood.hxx:894
static int dY(int code)
Definition: pixelneighborhood.hxx:281
static Diff2D const & southWest()
Definition: pixelneighborhood.hxx:612
Definition: pixelneighborhood.hxx:74
static Diff2D const & bottom()
Definition: pixelneighborhood.hxx:328
Diff2D const & southWest()
Definition: pixelneighborhood.hxx:636
bool operator==(NeighborOffsetCirculator const &o) const
Definition: pixelneighborhood.hxx:813
static Diff2D const & right()
Definition: pixelneighborhood.hxx:325
Definition: pixelneighborhood.hxx:182
base_type const & base() const
Definition: pixelneighborhood.hxx:1214
NeighborhoodCirculator operator-(difference_type d) const
Definition: pixelneighborhood.hxx:1098
Definition: pixelneighborhood.hxx:413
static Direction code(FourNeighborhood::Direction d)
Definition: pixelneighborhood.hxx:538
Diff2D const & west()
Definition: pixelneighborhood.hxx:635
int dX() const
Definition: pixelneighborhood.hxx:874
value_type const & index_reference
Definition: pixelneighborhood.hxx:689
FourNeighborhood::NeighborCode FourNeighborCode
Definition: pixelneighborhood.hxx:356
static Diff2D const & north()
Definition: pixelneighborhood.hxx:609
reference operator*() const
Definition: pixelneighborhood.hxx:1196
static const Direction East
Definition: pixelneighborhood.hxx:621
reference index_reference
Definition: pixelneighborhood.hxx:1023
static Diff2D const & relativeDiff(int fromCode, int toCode)
Definition: pixelneighborhood.hxx:522
static const Direction West
Definition: pixelneighborhood.hxx:343
Definition: pixelneighborhood.hxx:183
Definition: pixelneighborhood.hxx:70
NeighborOffsetCirculator & turnTo(Direction d)
Definition: pixelneighborhood.hxx:806
NeighborOffsetCirculator operator-(difference_type d) const
Definition: pixelneighborhood.hxx:769
Definition: pixelneighborhood.hxx:71
Definition: pixelneighborhood.hxx:72
Definition: pixelneighborhood.hxx:415
RestrictedNeighborhoodCirculator & operator+=(difference_type d)
Definition: pixelneighborhood.hxx:1384
static Diff2D const & south()
Definition: pixelneighborhood.hxx:333
Definition: pixelneighborhood.hxx:418
static Diff2D const & relativeDiff(Direction fromCode, Direction toCode)
Definition: pixelneighborhood.hxx:495
NeighborhoodCirculator & turnRight()
Definition: pixelneighborhood.hxx:1109
NEIGHBOROFFSETCIRCULATOR::value_type const & diff() const
Definition: pixelneighborhood.hxx:1238
static bool isDiagonal(Direction code)
Definition: pixelneighborhood.hxx:596
static Diff2D const & topLeft()
Definition: pixelneighborhood.hxx:601
NeighborOffsetCirculator & turnRight()
Definition: pixelneighborhood.hxx:778
IMAGEITERATOR base_type
Definition: pixelneighborhood.hxx:1310
IMAGEITERATOR::value_type value_type
Definition: pixelneighborhood.hxx:1010
EightNeighborhood::NeighborCode EightNeighborCode
Definition: pixelneighborhood.hxx:644
BaseType::value_type value_type
Definition: pixelneighborhood.hxx:1318
unsigned int oppositeDirectionBit() const
Definition: pixelneighborhood.hxx:915
Diff2D const & east()
Definition: pixelneighborhood.hxx:631
random_access_circulator_tag iterator_category
Definition: pixelneighborhood.hxx:701
bool operator==(NeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1176
value_type relativeDiff(difference_type offset) const
Definition: pixelneighborhood.hxx:865
Diff2D const & north()
Definition: pixelneighborhood.hxx:633
reference operator*() const
Definition: pixelneighborhood.hxx:831
Definition: pixelneighborhood.hxx:181
base_type center() const
Definition: pixelneighborhood.hxx:1450
Definition: pixelneighborhood.hxx:417
static Diff2D const & west()
Definition: pixelneighborhood.hxx:611
Diff2D const & northEast()
Definition: pixelneighborhood.hxx:632
NEIGHBOROFFSETCIRCULATOR::iterator_category iterator_category
Definition: pixelneighborhood.hxx:1035
static Diff2D const & right()
Definition: pixelneighborhood.hxx:598
Definition: pixelneighborhood.hxx:412
Definition: pixelneighborhood.hxx:187
value_type const & reference
Definition: pixelneighborhood.hxx:685
Encapsulation of direction management for the 8-neighborhood.
Definition: pixelneighborhood.hxx:397
static int dY(Direction code)
Definition: pixelneighborhood.hxx:530