Non-null regions will consist of connected, non-overlapping walkable spans that form a single contour. Contours will form simple polygons.
Watershed partitioning can result in smaller than necessary regions, especially in diagonal corridors. mergeRegionArea
helps reduce unecessarily small regions.
1539 const int w = chf.
width;
1540 const int h = chf.
height;
1551 const int LOG_NB_STACKS = 3;
1552 const int NB_STACKS = 1 << LOG_NB_STACKS;
1554 for (
int i=0; i<NB_STACKS; ++i)
1555 lvlStacks[i].resize(1024);
1560 unsigned short* srcReg = buf;
1561 unsigned short* srcDist = buf+chf.
spanCount;
1562 unsigned short* dstReg = buf+chf.
spanCount*2;
1563 unsigned short* dstDist = buf+chf.
spanCount*3;
1565 memset(srcReg, 0,
sizeof(
unsigned short)*chf.
spanCount);
1566 memset(srcDist, 0,
sizeof(
unsigned short)*chf.
spanCount);
1568 unsigned short regionId = 1;
1575 const int expandIters = 8;
1580 const int bw =
rcMin(w, borderSize);
1581 const int bh =
rcMin(h, borderSize);
1594 level = level >= 2 ? level-2 : 0;
1595 sId = (sId+1) & (NB_STACKS-1);
1602 appendStacks(lvlStacks[sId-1], lvlStacks[sId], srcReg);
1609 if (
expandRegions(expandIters, level, chf, srcReg, srcDist, dstReg, dstDist, lvlStacks[sId],
false) != srcReg)
1612 rcSwap(srcDist, dstDist);
1620 for (
int j=0; j<lvlStacks[sId].
size(); j+=3)
1622 int x = lvlStacks[sId][j];
1623 int y = lvlStacks[sId][j+1];
1624 int i = lvlStacks[sId][j+2];
1625 if (i >= 0 && srcReg[i] == 0)
1627 if (
floodRegion(x, y, i, level, regionId, chf, srcReg, srcDist, stack))
1636 if (
expandRegions(expandIters*8, 0, chf, srcReg, srcDist, dstReg, dstDist, stack,
true) != srcReg)
1639 rcSwap(srcDist, dstDist);
1653 if (overlaps.
size() > 0)
int height
The height of the heightfield. (Along the z-axis in cell units.)
Definition: Recast.h:308
#define rcAssert
Definition: RecastAssert.h:30
int borderSize
The AABB border size used during the build of the field. (See: rcConfig::borderSize) ...
Definition: Recast.h:312
unsigned short maxRegions
The maximum region id of any span within the field.
Definition: Recast.h:314
void rcSwap(T &a, T &b)
Definition: Recast.h:560
unsigned short reg
The id of the region the span belongs to. (Or zero if not in a region.)
Definition: Recast.h:298
static bool floodRegion(int x, int y, int i, unsigned short level, unsigned short r, rcCompactHeightfield &chf, unsigned short *srcReg, unsigned short *srcDist, rcIntArray &stack)
Definition: RecastRegion.cpp:244
int size() const
The current size of the integer array.
Definition: RecastAlloc.h:100
rcCompactSpan * spans
Array of spans. [Size: spanCount].
Definition: Recast.h:320
T rcMin(T a, T b)
Definition: Recast.h:566
An error log entry.
Definition: Recast.h:31
Definition: RecastAlloc.h:105
static bool mergeAndFilterRegions(rcContext *ctx, int minRegionArea, int mergeRegionSize, unsigned short &maxRegionId, rcCompactHeightfield &chf, unsigned short *srcReg, rcIntArray &overlaps)
Definition: RecastRegion.cpp:780
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
The total time to apply the watershed algorithm. (See: rcBuildRegions)
Definition: Recast.h:81
G3D::int16 y
Definition: Vector2int16.h:38
int width
The width of the heightfield. (Along the x-axis in cell units.)
Definition: Recast.h:307
The total time to build the regions. (See: rcBuildRegions, rcBuildRegionsMonotone) ...
Definition: Recast.h:79
void startTimer(const rcTimerLabel label)
Definition: Recast.h:131
static unsigned short * expandRegions(int maxIter, unsigned short level, rcCompactHeightfield &chf, unsigned short *srcReg, unsigned short *srcDist, unsigned short *dstReg, unsigned short *dstDist, rcIntArray &stack, bool fillStack)
Definition: RecastRegion.cpp:346
int spanCount
The number of spans in the heightfield.
Definition: Recast.h:309
static void paintRectRegion(int minx, int maxx, int miny, int maxy, unsigned short regId, rcCompactHeightfield &chf, unsigned short *srcReg)
Definition: RecastRegion.cpp:1309
The time to flood regions while applying the watershed algorithm. (See: rcBuildRegions) ...
Definition: Recast.h:85
The time to expand regions while applying the watershed algorithm. (See: rcBuildRegions) ...
Definition: Recast.h:83
static void sortCellsByLevel(unsigned short startLevel, rcCompactHeightfield &chf, unsigned short *srcReg, unsigned int nbStacks, rcIntArray *stacks, unsigned short loglevelsPerStack)
Definition: RecastRegion.cpp:459
unsigned short maxDistance
The maximum distance value of any span within the field.
Definition: Recast.h:313
Memory used temporarily within a function.
Definition: RecastAlloc.h:27
void log(const rcLogCategory category, const char *format,...)
Definition: Recast.cpp:55
G3D::int16 x
Definition: Vector2int16.h:37
void stopTimer(const rcTimerLabel label)
Definition: Recast.h:135
static const unsigned short RC_BORDER_REG
Definition: Recast.h:498
A simple dynamic array of integers.
Definition: RecastAlloc.h:61
The time to filter out small regions. (See: rcBuildRegions, rcBuildRegionsMonotone) ...
Definition: Recast.h:87
static void appendStacks(rcIntArray &srcStack, rcIntArray &dstStack, unsigned short *srcReg)
Definition: RecastRegion.cpp:499