Fix for issue 127.

This commit is contained in:
Mikko Mononen 2010-10-10 10:43:32 +00:00
parent f5c3a8b609
commit b429ee7304
5 changed files with 205 additions and 43 deletions

View File

@ -437,12 +437,19 @@ static unsigned short* expandRegions(int maxIter, unsigned short level,
struct rcRegion
{
inline rcRegion(unsigned short i) : count(0), id(i), area(0), remap(false) {}
inline rcRegion(unsigned short i) :
count(0),
id(i),
area(0),
remap(false),
visited(false)
{}
int count;
unsigned short id;
unsigned char area;
bool remap;
bool visited;
rcIntArray connections;
rcIntArray floors;
};
@ -760,7 +767,9 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionSize, int mergeRegio
}
}
// Remove too small unconnected regions.
// Remove too small regions.
rcIntArray stack(32);
rcIntArray trace(32);
for (int i = 0; i < nreg; ++i)
{
rcRegion& reg = regions[i];
@ -768,19 +777,62 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionSize, int mergeRegio
continue;
if (reg.count == 0)
continue;
if (reg.visited)
continue;
if (reg.connections.size() == 1 && reg.connections[0] == 0)
// Count the total size of all the connected regions.
// Also keep track of the regions connects to a tile border.
bool connectsToBorder = false;
int count = 0;
stack.resize(0);
trace.resize(0);
reg.visited = true;
stack.push(i);
while (stack.size())
{
if (reg.count < minRegionSize)
// Pop
int ri = stack.pop();
rcRegion& creg = regions[ri];
count += creg.count;
trace.push(ri);
for (int j = 0; j < creg.connections.size(); ++j)
{
// Non-connected small region, remove.
reg.count = 0;
reg.id = 0;
if (creg.connections[j] & RC_BORDER_REG)
{
connectsToBorder = true;
continue;
}
rcRegion& nreg = regions[creg.connections[j]];
if (nreg.visited)
continue;
if (nreg.id == 0 || (nreg.id & RC_BORDER_REG))
continue;
// Visit
stack.push(nreg.id);
nreg.visited = true;
}
}
// If the accumulated regions size is too small, remove it.
// Do not remove areas which connect to tile borders
// as their size cannot be estimated correctly and removing them
// can potentially remove necessary areas.
if (count < minRegionSize && !connectsToBorder)
{
// Kill all visited regions.
for (int j = 0; j < trace.size(); ++j)
{
regions[trace[j]].count = 0;
regions[trace[j]].id = 0;
}
}
}
// Merge too small regions to neighbour regions.
int mergeCount = 0 ;
do

View File

@ -210,6 +210,16 @@
6BB2EE281261C92300E350F8 /* PBXTextBookmark */ = 6BB2EE281261C92300E350F8 /* PBXTextBookmark */;
6BB2EE291261C92300E350F8 /* PBXTextBookmark */ = 6BB2EE291261C92300E350F8 /* PBXTextBookmark */;
6BB2EE2A1261C92300E350F8 /* PBXTextBookmark */ = 6BB2EE2A1261C92300E350F8 /* PBXTextBookmark */;
6BB2EE351261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE351261CEB800E350F8 /* PBXTextBookmark */;
6BB2EE361261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE361261CEB800E350F8 /* PBXTextBookmark */;
6BB2EE371261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE371261CEB800E350F8 /* PBXTextBookmark */;
6BB2EE381261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE381261CEB800E350F8 /* PBXTextBookmark */;
6BB2EE391261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE391261CEB800E350F8 /* PBXTextBookmark */;
6BB2EE3A1261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE3A1261CEB800E350F8 /* PBXTextBookmark */;
6BB2EE3E1261D02000E350F8 /* PBXTextBookmark */ = 6BB2EE3E1261D02000E350F8 /* PBXTextBookmark */;
6BB2EE3F1261D02000E350F8 /* PBXTextBookmark */ = 6BB2EE3F1261D02000E350F8 /* PBXTextBookmark */;
6BB2EE401261D02000E350F8 /* PBXTextBookmark */ = 6BB2EE401261D02000E350F8 /* PBXTextBookmark */;
6BB2EE411261D02000E350F8 /* PBXTextBookmark */ = 6BB2EE411261D02000E350F8 /* PBXTextBookmark */;
6BBB0361124E242E00533229 = 6BBB0361124E242E00533229 /* PBXTextBookmark */;
6BBB0363124E242E00533229 = 6BBB0363124E242E00533229 /* PBXTextBookmark */;
6BBB0365124E242E00533229 = 6BBB0365124E242E00533229 /* PBXTextBookmark */;
@ -365,9 +375,9 @@
};
6B137C830F7FCC1100459200 /* RecastContour.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {933, 12480}}";
sepNavIntBoundsRect = "{{0, 0}, {931, 9945}}";
sepNavSelRange = "{20095, 0}";
sepNavVisRange = "{19784, 431}";
sepNavVisRange = "{19389, 1374}";
sepNavWindowFrame = "{{38, 30}, {1214, 722}}";
};
};
@ -396,9 +406,9 @@
};
6B137C890F7FCC1100459200 /* RecastRegion.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {933, 18896}}";
sepNavSelRange = "{22176, 0}";
sepNavVisRange = "{21660, 751}";
sepNavIntBoundsRect = "{{0, 0}, {931, 17082}}";
sepNavSelRange = "{19532, 0}";
sepNavVisRange = "{17831, 971}";
};
};
6B1C8E08121EB4FF0048697F /* PBXTextBookmark */ = {
@ -420,9 +430,9 @@
};
6B25B6140FFA62BE004F1BC4 /* Sample.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {1219, 2470}}";
sepNavSelRange = "{1307, 0}";
sepNavVisRange = "{1241, 281}";
sepNavIntBoundsRect = "{{0, 0}, {931, 2769}}";
sepNavSelRange = "{2884, 0}";
sepNavVisRange = "{2623, 1223}";
};
};
6B25B6180FFA62BE004F1BC4 /* main.cpp */ = {
@ -500,9 +510,9 @@
};
6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {931, 6045}}";
sepNavSelRange = "{1110, 0}";
sepNavVisRange = "{789, 626}";
sepNavIntBoundsRect = "{{0, 0}, {931, 5954}}";
sepNavSelRange = "{1003, 0}";
sepNavVisRange = "{842, 1275}";
};
};
6B555DF6100B273500247EA3 /* stb_truetype.h */ = {
@ -810,7 +820,7 @@
fRef = 6B137C890F7FCC1100459200 /* RecastRegion.cpp */;
name = "RecastRegion.cpp: 931";
rLen = 0;
rLoc = 22176;
rLoc = 23307;
rType = 0;
vrLen = 751;
vrLoc = 21660;
@ -856,9 +866,9 @@
};
6B98470511E733B600FA177B /* RecastAlloc.h */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {933, 1120}}";
sepNavSelRange = "{2032, 0}";
sepNavVisRange = "{1347, 951}";
sepNavIntBoundsRect = "{{0, 0}, {931, 910}}";
sepNavSelRange = "{1797, 71}";
sepNavVisRange = "{969, 1378}";
};
};
6B98473011E737D800FA177B /* PBXTextBookmark */ = {
@ -894,9 +904,9 @@
};
6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {1219, 8281}}";
sepNavSelRange = "{8071, 18}";
sepNavVisRange = "{7496, 602}";
sepNavIntBoundsRect = "{{0, 0}, {931, 8307}}";
sepNavSelRange = "{11545, 0}";
sepNavVisRange = "{10675, 1806}";
};
};
6BA1E88E10C7BFD3008007F6 /* Sample_SoloMeshSimple.h */ = {
@ -1656,6 +1666,106 @@
vrLen = 626;
vrLoc = 789;
};
6BB2EE351261CEB800E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */;
name = "imguiRenderGL.cpp: 22";
rLen = 0;
rLoc = 1003;
rType = 0;
vrLen = 1275;
vrLoc = 842;
};
6BB2EE361261CEB800E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6B98470511E733B600FA177B /* RecastAlloc.h */;
name = "RecastAlloc.h: 51";
rLen = 71;
rLoc = 1797;
rType = 0;
vrLen = 1378;
vrLoc = 969;
};
6BB2EE371261CEB800E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6B137C890F7FCC1100459200 /* RecastRegion.cpp */;
name = "RecastRegion.cpp: 849";
rLen = 0;
rLoc = 19562;
rType = 0;
vrLen = 1078;
vrLoc = 19104;
};
6BB2EE381261CEB800E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */;
name = "Sample_SoloMeshSimple.cpp: 380";
rLen = 0;
rLoc = 11545;
rType = 0;
vrLen = 1806;
vrLoc = 10675;
};
6BB2EE391261CEB800E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */;
name = "Sample.cpp: 121";
rLen = 15;
rLoc = 2865;
rType = 0;
vrLen = 1409;
vrLoc = 3254;
};
6BB2EE3A1261CEB800E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */;
name = "Sample.cpp: 121";
rLen = 0;
rLoc = 2884;
rType = 0;
vrLen = 1152;
vrLoc = 2586;
};
6BB2EE3E1261D02000E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */;
name = "Sample.cpp: 121";
rLen = 0;
rLoc = 2884;
rType = 0;
vrLen = 1223;
vrLoc = 2623;
};
6BB2EE3F1261D02000E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6B137C830F7FCC1100459200 /* RecastContour.cpp */;
name = "RecastContour.cpp: 752";
rLen = 0;
rLoc = 20095;
rType = 0;
vrLen = 1374;
vrLoc = 19389;
};
6BB2EE401261D02000E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6B137C890F7FCC1100459200 /* RecastRegion.cpp */;
name = "RecastRegion.cpp: 849";
rLen = 0;
rLoc = 19562;
rType = 0;
vrLen = 1093;
vrLoc = 19103;
};
6BB2EE411261D02000E350F8 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 6B137C890F7FCC1100459200 /* RecastRegion.cpp */;
name = "RecastRegion.cpp: 830";
rLen = 0;
rLoc = 19532;
rType = 0;
vrLen = 971;
vrLoc = 17831;
};
6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {933, 3712}}";

View File

@ -284,7 +284,7 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>29</integer>
<integer>34</integer>
<integer>27</integer>
<integer>1</integer>
<integer>0</integer>
@ -326,7 +326,7 @@
<key>PBXProjectModuleGUID</key>
<string>6B8632A30F78115100E2684A</string>
<key>PBXProjectModuleLabel</key>
<string>imguiRenderGL.cpp</string>
<string>RecastRegion.cpp</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
@ -334,11 +334,11 @@
<key>PBXProjectModuleGUID</key>
<string>6B8632A40F78115100E2684A</string>
<key>PBXProjectModuleLabel</key>
<string>imguiRenderGL.cpp</string>
<string>RecastRegion.cpp</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>6BB2EE2A1261C92300E350F8</string>
<string>6BB2EE411261D02000E350F8</string>
<key>history</key>
<array>
<string>6BBB4AA5115B4F3400CF791D</string>
@ -357,7 +357,6 @@
<string>6BAF46D3121D8FF1008CFCDF</string>
<string>6B1C8E08121EB4FF0048697F</string>
<string>6BA6876E1222F02E00730711</string>
<string>6BA687831222F42100730711</string>
<string>6BA687881222F4DB00730711</string>
<string>6BA687CA1222FA9300730711</string>
<string>6BD402111224336600995864</string>
@ -370,9 +369,7 @@
<string>6BD402B4122441CB00995864</string>
<string>6B920A521225C0AC00D5B5AD</string>
<string>6B920A6D1225C5DD00D5B5AD</string>
<string>6B920AA81225DBCB00D5B5AD</string>
<string>6BA7F8AC1226EF0400C8C47A</string>
<string>6BA7F8D01226EF9D00C8C47A</string>
<string>6BA7F8EC1227002300C8C47A</string>
<string>6BA7F8ED1227002300C8C47A</string>
<string>6BA7F8EE1227002300C8C47A</string>
@ -412,8 +409,6 @@
<string>6BA8CF501255D44700272A3B</string>
<string>6BA8CF511255D44700272A3B</string>
<string>6BA8CF5B1255D49B00272A3B</string>
<string>6BA8CF6F1255D50700272A3B</string>
<string>6BA8CF7B1255D5FE00272A3B</string>
<string>6BA8CF7C1255D5FE00272A3B</string>
<string>6BA8CF941255D97400272A3B</string>
<string>6BA8CF951255D97400272A3B</string>
@ -430,7 +425,12 @@
<string>6BB2EE261261C92300E350F8</string>
<string>6BB2EE271261C92300E350F8</string>
<string>6BB2EE281261C92300E350F8</string>
<string>6BB2EE291261C92300E350F8</string>
<string>6BB2EE351261CEB800E350F8</string>
<string>6BB2EE361261CEB800E350F8</string>
<string>6BB2EE381261CEB800E350F8</string>
<string>6BB2EE3E1261D02000E350F8</string>
<string>6BB2EE3F1261D02000E350F8</string>
<string>6BB2EE401261D02000E350F8</string>
</array>
</dict>
<key>SplitCount</key>
@ -444,18 +444,18 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {992, 379}}</string>
<string>{{0, 0}, {992, 673}}</string>
<key>RubberWindowFrame</key>
<string>0 59 1278 719 0 0 1280 778 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
<string>379pt</string>
<string>673pt</string>
</dict>
<dict>
<key>Proportion</key>
<string>294pt</string>
<string>0pt</string>
<key>Tabs</key>
<array>
<dict>
@ -485,7 +485,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {992, 267}}</string>
<string>{{10, 27}, {992, -27}}</string>
<key>RubberWindowFrame</key>
<string>0 59 1278 719 0 0 1280 778 </string>
</dict>

View File

@ -118,7 +118,7 @@ void Sample::resetCommonSettings()
m_agentRadius = 0.6f;
m_agentMaxClimb = 0.9f;
m_agentMaxSlope = 45.0f;
m_regionMinSize = 50;
m_regionMinSize = 8;
m_regionMergeSize = 20;
m_edgeMaxLen = 12.0f;
m_edgeMaxError = 1.3f;