36 #ifndef VIGRA_PIXELNEIGHBORHOOD_HXX 37 #define VIGRA_PIXELNEIGHBORHOOD_HXX 132 namespace FourNeighborhood
191 InitialDirection =
East,
192 OppositeDirPrefix = 1,
193 OppositeOffset =
West 199 static unsigned int b[];
200 static unsigned int c[];
206 static unsigned int directionBit(
Direction d)
208 return StaticData<0>::b[d];
215 return StaticData<0>::c[b];
223 return StaticData<0>::bd[b][index];
231 return StaticData<0>::d[
code];
245 return StaticData<0>::rd[fromCode][toCode];
253 return relativeDiff(static_cast<Direction>(fromCode), static_cast<Direction>(toCode));
287 return (diff.
y == 0) ?
293 return (diff.
y == 0) ?
337 unsigned int NeighborCode::StaticData<DUMMY>::b[] = {1 <<
East,
343 unsigned int NeighborCode::StaticData<DUMMY>::c[] = { 4, 3, 3, 0, 3, 2, 2, 0, 3, 2, 2};
346 Direction NeighborCode::StaticData<DUMMY>::bd[11][4] = {
361 Diff2D NeighborCode::StaticData<DUMMY>::d[] = {
366 Diff2D NeighborCode::StaticData<DUMMY>::rd[][4] = {
388 namespace EightNeighborhood
450 InitialDirection =
East,
451 OppositeDirPrefix = 1,
452 OppositeOffset =
West 458 static unsigned int b[];
459 static unsigned int c[];
465 static unsigned int directionBit(
Direction d)
467 return StaticData<0>::b[d];
474 return StaticData<0>::c[b];
482 return StaticData<0>::bd[b][index];
490 return StaticData<0>::d[
code];
504 return StaticData<0>::rd[fromCode][toCode];
512 return relativeDiff(static_cast<Direction>(fromCode), static_cast<Direction>(toCode));
610 static const Direction
NorthEast = NeighborCode::NorthEast;
612 static const Direction
NorthWest = NeighborCode::NorthWest;
614 static const Direction
SouthWest = NeighborCode::SouthWest;
616 static const Direction
SouthEast = NeighborCode::SouthEast;
629 unsigned int NeighborCode::StaticData<DUMMY>::b[] = {
640 unsigned int NeighborCode::StaticData<DUMMY>::c[] = { 8, 5, 5, 0, 5, 3, 3, 0, 5, 3, 3};
643 Direction NeighborCode::StaticData<DUMMY>::bd[11][8] = {
658 Diff2D NeighborCode::StaticData<DUMMY>::d[] = {
664 Diff2D NeighborCode::StaticData<DUMMY>::rd[][8] = {
711 template<
class NEIGHBORCODE>
713 :
public NEIGHBORCODE
716 typedef NEIGHBORCODE NeighborCode;
747 Direction direction_;
760 direction_ =
static_cast<Direction
>((direction_+1) % NEIGHBORCODE::DirectionCount);
767 direction_ =
static_cast<Direction
>((direction_ + NEIGHBORCODE::DirectionCount-1) % NEIGHBORCODE::DirectionCount);
790 direction_ =
static_cast<Direction
>((direction_ + d) % NEIGHBORCODE::DirectionCount);
792 direction_ =
static_cast<Direction
>(direction_ + NEIGHBORCODE::DirectionCount);
799 direction_ =
static_cast<Direction
>((direction_ - d) % NEIGHBORCODE::DirectionCount);
801 direction_ =
static_cast<Direction
>(direction_ + NEIGHBORCODE::DirectionCount);
823 direction_ =
static_cast<Direction
>((direction_ + NEIGHBORCODE::South) % NEIGHBORCODE::DirectionCount);
833 direction_ =
static_cast<Direction
>((direction_ + NEIGHBORCODE::North) % NEIGHBORCODE::DirectionCount);
843 direction_ = opposite();
858 return direction_ == o.direction_;
864 return direction_ != o.direction_;
870 return direction_ - o.direction_;
882 return NEIGHBORCODE::diff(direction(d));
895 return NEIGHBORCODE::diff(direction_);
900 static reference
diff(Direction dir)
902 return NEIGHBORCODE::diff(dir);
910 Direction toDir =
static_cast<Direction
>((direction_ + offset) % NEIGHBORCODE::DirectionCount);
912 toDir =
static_cast<Direction
>(toDir + NEIGHBORCODE::DirectionCount);
913 return NEIGHBORCODE::relativeDiff(direction_, toDir);
919 return NEIGHBORCODE::dX(direction_);
925 return NEIGHBORCODE::dY(direction_);
932 return NEIGHBORCODE::isDiagonal(direction_);
946 return NEIGHBORCODE::directionBit(direction_);
953 return static_cast<Direction
>((NEIGHBORCODE::OppositeDirPrefix*direction_ + NEIGHBORCODE::OppositeOffset) % NEIGHBORCODE::DirectionCount);
960 return NEIGHBORCODE::directionBit(opposite());
967 int result = (direction_ + offset) % NEIGHBORCODE::DirectionCount;
969 result += NEIGHBORCODE::DirectionCount;
970 return static_cast<Direction
>(result);
1036 template <
class IMAGEITERATOR,
class NEIGHBORCODE>
1084 Direction d = NEIGHBOROFFSETCIRCULATOR::InitialDirection)
1085 : IMAGEITERATOR(aCenter), neighborCode_(d)
1154 Direction oldDirection = neighborCode_.
direction();
1155 neighborCode_.turnRight();
1157 (oldDirection, neighborCode_.direction()));
1167 Direction oldDirection = neighborCode_.
direction();
1168 neighborCode_.turnLeft();
1170 (oldDirection, neighborCode_.direction()));
1180 Direction oldDirection = neighborCode_.
direction();
1181 neighborCode_.turnRound();
1183 (oldDirection, neighborCode_.direction()));
1191 Direction oldDirection = neighborCode_.
direction();
1192 neighborCode_.turnTo(d);
1194 (oldDirection, neighborCode_.direction()));
1221 return neighborCode_ == rhs.neighborCode_ &&
1228 return neighborCode_ != rhs.neighborCode_ ||
1235 return neighborCode_ - rhs.neighborCode_;
1241 return IMAGEITERATOR::operator*();
1247 return IMAGEITERATOR::operator[](neighborCode_.relativeDiff(d));
1253 return IMAGEITERATOR::operator->();
1265 return (base_type)*
this - neighborCode_.diff();
1271 return neighborCode_.direction();
1277 return neighborCode_.directionBit();
1283 return neighborCode_.diff();
1289 return neighborCode_.isDiagonal();
1293 NEIGHBOROFFSETCIRCULATOR neighborCode_;
1344 template <
class IMAGEITERATOR,
class NEIGHBORCODE>
1393 whichBorder_(atBorder),
1429 current_ =
static_cast<Direction
>((current_ + count_ + d) % count_);
1430 BaseType::turnTo(NEIGHBORCODE::nearBorderDirections(whichBorder_, current_));
1459 return current_ == rhs.current_;
1465 return current_ != rhs.current_;
1471 return (current_ - rhs.current_) % count_;
1477 return BaseType::operator*();
1483 return BaseType::operator->();
1489 return BaseType::base();
1495 return BaseType::center();
1501 return BaseType::direction();
1507 return BaseType::directionBit();
1511 typename NeighborCode::difference_type
const &
diff()
const 1513 return BaseType::diff();
1519 return BaseType::isDiagonal();
1524 signed char count_, current_;
RestrictedNeighborhoodCirculator(IMAGEITERATOR const ¢er=IMAGEITERATOR(), AtImageBorder atBorder=NotAtBorder)
Definition: pixelneighborhood.hxx:1390
unsigned int directionBit() const
Definition: pixelneighborhood.hxx:944
static Diff2D const & southEast()
Definition: pixelneighborhood.hxx:602
pointer operator->() const
Definition: pixelneighborhood.hxx:1481
Direction direction() const
Definition: pixelneighborhood.hxx:1499
static Diff2D const & west()
Definition: pixelneighborhood.hxx:314
 
Definition: pixelneighborhood.hxx:186
NEIGHBORCODE::Direction Direction
Definition: pixelneighborhood.hxx:1057
reference operator*() const
Definition: pixelneighborhood.hxx:1239
NeighborhoodCirculator & operator-=(difference_type d)
Definition: pixelneighborhood.hxx:1127
reference diff() const
Definition: pixelneighborhood.hxx:893
NeighborOffsetCirculator & turnRound()
Definition: pixelneighborhood.hxx:841
RestrictedNeighborhoodCirculator & operator-=(difference_type d)
Definition: pixelneighborhood.hxx:1435
 
Definition: pixelneighborhood.hxx:443
static Diff2D const & top()
Definition: pixelneighborhood.hxx:588
Circulator that walks around a given location in a given image, using a restricted neighborhood...
Definition: pixelneighborhood.hxx:1345
static Diff2D const & north()
Definition: pixelneighborhood.hxx:313
IMAGEITERATOR base_type
Definition: pixelneighborhood.hxx:1045
static int dX(Direction code)
Definition: pixelneighborhood.hxx:257
 
Definition: pixelneighborhood.hxx:437
NeighborhoodCirculator operator--(int)
Definition: pixelneighborhood.hxx:1111
bool isDiagonal() const
Definition: pixelneighborhood.hxx:1517
int y
Definition: diff2d.hxx:392
Direction
Definition: pixelneighborhood.hxx:434
BaseType::index_reference index_reference
Definition: pixelneighborhood.hxx:1373
 
Definition: pixelneighborhood.hxx:439
static Diff2D const & top()
Definition: pixelneighborhood.hxx:308
static const Direction SouthWest
Definition: pixelneighborhood.hxx:614
 
Definition: pixelneighborhood.hxx:188
RestrictedNeighborhoodCirculator operator--(int)
Definition: pixelneighborhood.hxx:1419
Direction direction(difference_type offset) const
Definition: pixelneighborhood.hxx:965
Direction opposite() const
Definition: pixelneighborhood.hxx:951
RestrictedNeighborhoodCirculator & operator--()
Definition: pixelneighborhood.hxx:1413
Direction direction() const
Definition: pixelneighborhood.hxx:1269
NEIGHBOROFFSETCIRCULATOR::value_type const & diff() const
Definition: pixelneighborhood.hxx:1281
NEIGHBORCODE NeighborCode
Definition: pixelneighborhood.hxx:1049
NeighborhoodCirculator operator-(difference_type d) const
Definition: pixelneighborhood.hxx:1141
static Diff2D const & diff(Direction code)
Definition: pixelneighborhood.hxx:488
static bool isDiagonal(Direction)
Definition: pixelneighborhood.hxx:305
NeighborOffsetCirculator & turnLeft()
Definition: pixelneighborhood.hxx:831
NeighborOffsetCirculator< FourNeighborCode > FourNeighborOffsetCirculator
Definition: pixelneighborhood.hxx:980
reference operator*() const
Definition: pixelneighborhood.hxx:1475
bool operator!=(NeighborOffsetCirculator const &o) const
Definition: pixelneighborhood.hxx:862
 
Definition: pixelneighborhood.hxx:189
NeighborOffsetCirculator(Direction dir=NEIGHBORCODE::InitialDirection)
Definition: pixelneighborhood.hxx:752
static unsigned int nearBorderDirectionCount(AtImageBorder b)
Definition: pixelneighborhood.hxx:213
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:788
static Diff2D const & northWest()
Definition: pixelneighborhood.hxx:598
static Diff2D const & topRight()
Definition: pixelneighborhood.hxx:587
BaseType::pointer pointer
Definition: pixelneighborhood.hxx:1377
 
Definition: pixelneighborhood.hxx:444
NEIGHBORCODE::Direction Direction
Definition: pixelneighborhood.hxx:720
Two dimensional difference vector.
Definition: diff2d.hxx:185
base_type center() const
Definition: pixelneighborhood.hxx:1493
IMAGEITERATOR::pointer pointer
Definition: pixelneighborhood.hxx:1070
RestrictedNeighborhoodCirculator operator-(difference_type d) const
Definition: pixelneighborhood.hxx:1449
AtImageBorder isAtImageBorder(int x, int y, int width, int height)
Find out whether a point is at the image border.
Definition: pixelneighborhood.hxx:111
NeighborOffsetCirculator operator-(difference_type d) const
Definition: pixelneighborhood.hxx:812
static Diff2D const & left()
Definition: pixelneighborhood.hxx:309
NeighborOffsetCirculator operator++(int)
Definition: pixelneighborhood.hxx:772
RestrictedNeighborhoodCirculator operator+(difference_type d) const
Definition: pixelneighborhood.hxx:1441
NeighborOffsetCirculator< EightNeighborCode > EightNeighborOffsetCirculator
Definition: pixelneighborhood.hxx:976
static unsigned int nearBorderDirectionCount(AtImageBorder b)
Definition: pixelneighborhood.hxx:472
NeighborOffsetCirculator operator--(int)
Definition: pixelneighborhood.hxx:780
 
Definition: pixelneighborhood.hxx:185
BaseType::reference reference
Definition: pixelneighborhood.hxx:1369
int difference_type
Definition: pixelneighborhood.hxx:740
NeighborhoodCirculator & operator++()
Definition: pixelneighborhood.hxx:1091
bool isDiagonal() const
Definition: pixelneighborhood.hxx:930
static Direction nearBorderDirections(AtImageBorder b, int index)
Definition: pixelneighborhood.hxx:480
Encapsulation of direction management for 4-neighborhood.
Definition: pixelneighborhood.hxx:165
 
Definition: pixelneighborhood.hxx:73
reference operator*() const
Definition: pixelneighborhood.hxx:874
IMAGEITERATOR::reference reference
Definition: pixelneighborhood.hxx:1061
int dX() const
Definition: pixelneighborhood.hxx:917
static Diff2D const & south()
Definition: pixelneighborhood.hxx:601
static int dY(int code)
Definition: pixelneighborhood.hxx:522
NeighborhoodCirculator & moveCenterToNeighbor()
Definition: pixelneighborhood.hxx:1201
static Diff2D const & left()
Definition: pixelneighborhood.hxx:590
NeighborhoodCirculator & turnRound()
Definition: pixelneighborhood.hxx:1178
static Diff2D const & east()
Definition: pixelneighborhood.hxx:595
NeighborhoodCirculator & turnTo(Direction d)
Definition: pixelneighborhood.hxx:1189
NeighborhoodCirculator & operator+=(difference_type d)
Definition: pixelneighborhood.hxx:1119
static Diff2D const & bottomLeft()
Definition: pixelneighborhood.hxx:591
bool isDiagonal() const
Definition: pixelneighborhood.hxx:1287
NeighborOffsetCirculator & operator-=(difference_type d)
Definition: pixelneighborhood.hxx:797
Direction
Definition: pixelneighborhood.hxx:179
NEIGHBOROFFSETCIRCULATOR::difference_type difference_type
Definition: pixelneighborhood.hxx:1074
unsigned int oppositeDirectionBit() const
Definition: pixelneighborhood.hxx:958
static Diff2D const & diff(Direction code)
Definition: pixelneighborhood.hxx:229
Circulator that walks around a given location.
Definition: pixelneighborhood.hxx:712
 
Definition: pixelneighborhood.hxx:442
NEIGHBORCODE::difference_type value_type
Definition: pixelneighborhood.hxx:724
RestrictedNeighborhoodCirculator operator++(int)
Definition: pixelneighborhood.hxx:1405
FFTWComplex< R > & operator+=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
add-assignment
Definition: fftw3.hxx:859
value_type relativeDiff(difference_type offset) const
Definition: pixelneighborhood.hxx:908
static const Direction NorthWest
Definition: pixelneighborhood.hxx:612
static Diff2D const & diff(int code)
Definition: pixelneighborhood.hxx:237
Diff2D const & northWest()
Definition: pixelneighborhood.hxx:622
static int dY(Direction code)
Definition: pixelneighborhood.hxx:259
value_type const * pointer
Definition: pixelneighborhood.hxx:736
static Direction nearBorderDirections(AtImageBorder b, int index)
Definition: pixelneighborhood.hxx:221
NEIGHBORCODE NeighborCode
Definition: pixelneighborhood.hxx:1357
bool operator!=(RestrictedNeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1463
NeighborhoodCirculator operator+(difference_type d) const
Definition: pixelneighborhood.hxx:1133
unsigned int directionBit() const
Definition: pixelneighborhood.hxx:1275
 
Definition: pixelneighborhood.hxx:180
bool operator==(NeighborOffsetCirculator const &o) const
Definition: pixelneighborhood.hxx:856
difference_type operator-(NeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1233
 
Definition: pixelneighborhood.hxx:184
static Diff2D const & diff(int code)
Definition: pixelneighborhood.hxx:496
NeighborhoodCirculator & turnLeft()
Definition: pixelneighborhood.hxx:1165
bool operator!=(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
not equal
Definition: fftw3.hxx:841
static const Direction NorthEast
Definition: pixelneighborhood.hxx:610
static int dX(Direction code)
Definition: pixelneighborhood.hxx:516
static Diff2D const & bottomRight()
Definition: pixelneighborhood.hxx:593
static Diff2D const & relativeDiff(int fromCode, int toCode)
Definition: pixelneighborhood.hxx:251
bool operator==(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
equal
Definition: fftw3.hxx:825
BaseType::difference_type difference_type
Definition: pixelneighborhood.hxx:1381
static Direction code(Diff2D const &diff)
Definition: pixelneighborhood.hxx:269
Circulator that walks around a given location in a given image.
Definition: pixelneighborhood.hxx:1037
static Diff2D const & northEast()
Definition: pixelneighborhood.hxx:596
NeighborOffsetCirculator & operator++()
Definition: pixelneighborhood.hxx:758
NeighborOffsetCirculator operator+(difference_type d) const
Definition: pixelneighborhood.hxx:806
NeighborhoodCirculator & operator--()
Definition: pixelneighborhood.hxx:1105
base_type const & base() const
Definition: pixelneighborhood.hxx:1487
static const Direction SouthEast
Definition: pixelneighborhood.hxx:616
base_type center() const
Definition: pixelneighborhood.hxx:1263
NeighborhoodCirculator & swapCenterNeighbor()
Definition: pixelneighborhood.hxx:1211
static Diff2D const & relativeDiff(Direction fromCode, Direction toCode)
Definition: pixelneighborhood.hxx:243
pointer operator->() const
Definition: pixelneighborhood.hxx:1251
NeighborhoodCirculator operator++(int)
Definition: pixelneighborhood.hxx:1097
pointer operator->() const
Definition: pixelneighborhood.hxx:886
int dY() const
Definition: pixelneighborhood.hxx:923
static Diff2D const & east()
Definition: pixelneighborhood.hxx:312
static Direction code(Diff2D const &diff)
Definition: pixelneighborhood.hxx:533
static int dX(int code)
Definition: pixelneighborhood.hxx:520
BaseType::iterator_category iterator_category
Definition: pixelneighborhood.hxx:1385
static Diff2D const & bottom()
Definition: pixelneighborhood.hxx:592
BaseType::Direction Direction
Definition: pixelneighborhood.hxx:1365
static reference diff(Direction dir)
Definition: pixelneighborhood.hxx:900
static int dX(int code)
Definition: pixelneighborhood.hxx:261
bool operator!=(NeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1226
bool operator==(RestrictedNeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1457
NeighborOffsetCirculator & operator--()
Definition: pixelneighborhood.hxx:765
difference_type operator-(NeighborOffsetCirculator const &o) const
Definition: pixelneighborhood.hxx:868
RestrictedNeighborhoodCirculator & operator++()
Definition: pixelneighborhood.hxx:1399
Diff2D const & southEast()
Definition: pixelneighborhood.hxx:626
base_type const & base() const
Definition: pixelneighborhood.hxx:1257
static int dY(int code)
Definition: pixelneighborhood.hxx:263
static Diff2D const & southWest()
Definition: pixelneighborhood.hxx:600
 
Definition: pixelneighborhood.hxx:74
static Diff2D const & bottom()
Definition: pixelneighborhood.hxx:310
Diff2D const & southWest()
Definition: pixelneighborhood.hxx:624
static Diff2D const & right()
Definition: pixelneighborhood.hxx:307
 
Definition: pixelneighborhood.hxx:182
bool operator==(NeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1219
static Direction code(FourNeighborhood::Direction d)
Definition: pixelneighborhood.hxx:526
NeighborCode::difference_type const & diff() const
Definition: pixelneighborhood.hxx:1511
index_reference operator[](difference_type d) const
Definition: pixelneighborhood.hxx:1245
value_type const & index_reference
Definition: pixelneighborhood.hxx:732
unsigned int directionBit() const
Definition: pixelneighborhood.hxx:1505
FourNeighborhood::NeighborCode FourNeighborCode
Definition: pixelneighborhood.hxx:379
static Diff2D const & north()
Definition: pixelneighborhood.hxx:597
reference index_reference
Definition: pixelneighborhood.hxx:1066
static Diff2D const & relativeDiff(int fromCode, int toCode)
Definition: pixelneighborhood.hxx:510
Direction direction() const
Definition: pixelneighborhood.hxx:937
 
Definition: pixelneighborhood.hxx:183
 
Definition: pixelneighborhood.hxx:70
NeighborOffsetCirculator & turnTo(Direction d)
Definition: pixelneighborhood.hxx:849
 
Definition: pixelneighborhood.hxx:71
index_reference operator[](difference_type d) const
Definition: pixelneighborhood.hxx:880
 
Definition: pixelneighborhood.hxx:72
 
Definition: pixelneighborhood.hxx:438
RestrictedNeighborhoodCirculator & operator+=(difference_type d)
Definition: pixelneighborhood.hxx:1427
static Diff2D const & south()
Definition: pixelneighborhood.hxx:315
 
Definition: pixelneighborhood.hxx:441
static Diff2D const & relativeDiff(Direction fromCode, Direction toCode)
Definition: pixelneighborhood.hxx:502
NeighborhoodCirculator & turnRight()
Definition: pixelneighborhood.hxx:1152
static bool isDiagonal(Direction code)
Definition: pixelneighborhood.hxx:584
static Diff2D const & topLeft()
Definition: pixelneighborhood.hxx:589
NeighborOffsetCirculator & turnRight()
Definition: pixelneighborhood.hxx:821
IMAGEITERATOR base_type
Definition: pixelneighborhood.hxx:1353
IMAGEITERATOR::value_type value_type
Definition: pixelneighborhood.hxx:1053
EightNeighborhood::NeighborCode EightNeighborCode
Definition: pixelneighborhood.hxx:687
BaseType::value_type value_type
Definition: pixelneighborhood.hxx:1361
random_access_circulator_tag iterator_category
Definition: pixelneighborhood.hxx:744
 
Definition: pixelneighborhood.hxx:181
 
Definition: pixelneighborhood.hxx:440
static Diff2D const & west()
Definition: pixelneighborhood.hxx:599
difference_type operator-(RestrictedNeighborhoodCirculator const &rhs) const
Definition: pixelneighborhood.hxx:1469
Diff2D const & northEast()
Definition: pixelneighborhood.hxx:620
NEIGHBOROFFSETCIRCULATOR::iterator_category iterator_category
Definition: pixelneighborhood.hxx:1078
static Diff2D const & right()
Definition: pixelneighborhood.hxx:586
NeighborhoodCirculator(IMAGEITERATOR const &aCenter=IMAGEITERATOR(), Direction d=NEIGHBOROFFSETCIRCULATOR::InitialDirection)
Definition: pixelneighborhood.hxx:1083
 
Definition: pixelneighborhood.hxx:187
value_type const & reference
Definition: pixelneighborhood.hxx:728
Encapsulation of direction management for the 8-neighborhood.
Definition: pixelneighborhood.hxx:420
static int dY(Direction code)
Definition: pixelneighborhood.hxx:518