Class CleanNullRegionBorders

  extended by org.critterai.nmgen.CleanNullRegionBorders
All Implemented Interfaces:

public class CleanNullRegionBorders
extends Object
implements IOpenHeightFieldAlgorithm

Implements three algorithms that clean up issues that can develop around null region boarders.

Detect and fix encompassed null regions:

If a null region is found that is fully encompassed by a single region, then the region will be split into two regions at the null region border.

Detect and fix "short wrapping" of null regions:

Regions can sometimes wrap slightly around the corner of a null region in a manner that eventually results in the formation of self-intersecting polygons.

Example: Before the algorithm is applied:

Example: After the algorithm is applied:

Detect and fix incomplete null region connections:

If a region touches null region only diagonally, then contour detection algorithms may not properly detect the null region connection. This can adversely effect other algorithms in the pipeline.

Example: Before algorithm is applied:

     b b a a a a
     b b a a a a
     a a x x x x
     a a x x x x

Example: After algorithm is applied:

     b b a a a a
     b b b a a a <-- Span transferred to region B.
     a a x x x x
     a a x x x x

See Also:
Region Generation

Constructor Summary
CleanNullRegionBorders(boolean useOnlyNullRegionSpans)
Method Summary
 void apply(OpenHeightfield field)
          Applies the algorithm to the height field.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public CleanNullRegionBorders(boolean useOnlyNullRegionSpans)

Choosing a contour detection type:

This algorithm has to detect and walk null region contours. (Where null regions border non-null regions.) There are two options for detection: Search every single span looking for null region neighbors. Or search only null region spans looking for non-null region neighbors. Since null region spans are only a tiny fraction of total spans, the second option has better performance.

If a heightfield is constructed such that all null regions have at least one null region span in each contour, then set useOnlyNullRegionSpans to TRUE.

useOnlyNullRegionSpans - If TRUE, then only null region spans will be used to initially detect null region borders. This improves performance. If FALSE, all spans are searched to detect borders.
Method Detail


public void apply(OpenHeightfield field)
Applies the algorithm to the height field.

This operation utilizes OpenHeightSpan.flags. It expects the value to be zero on entry, and re-zero's the value on exit.

Expects a heightfield with fully built regions.

Specified by:
apply in interface IOpenHeightFieldAlgorithm
field - The field to apply the algorithm to.

Project Home and Source Code

Copyright 2010 Stephen Pratt. All rights reserved. Use is subject to license terms.