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_;
867 Direction toDir =
static_cast<Direction>((direction_ + offset) % NEIGHBORCODE::DirectionCount);
869 toDir =
static_cast<Direction>(toDir + NEIGHBORCODE::DirectionCount);
910 return static_cast<Direction>((NEIGHBORCODE::OppositeDirPrefix*direction_ + NEIGHBORCODE::OppositeOffset) % NEIGHBORCODE::DirectionCount);
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_;
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_;