org.critterai.nmgen
Class SolidHeightfield

java.lang.Object
  extended by org.critterai.nmgen.BoundedField
      extended by org.critterai.nmgen.SolidHeightfield

public final class SolidHeightfield
extends BoundedField

Contains data that represents the obstructed (solid) area of a bounded field of voxels.

The data is stored within spans which represent a vertically contiguous group of solid voxels. A reference to the lowest span within a grid location is stored at that grid location's width/depth index. Height spans further up in the grid's column can be accessed via HeightSpan.next() on the base span. (I.e. By climbing up the links.)

See Also:
SolidHeightfieldBuilder, The Voxelization Process, Introduction to Height Fields

Nested Class Summary
 class SolidHeightfield.SolidHeightFieldIterator
          Implements an iterator that will iterate through all spans within a height field.
 
Constructor Summary
SolidHeightfield(float cellSize, float cellHeight)
          Constructor
 
Method Summary
 boolean addData(int widthIndex, int depthIndex, int heightIndexMin, int heightIndexMax, int flags)
          Adds span data to the heightfield.
 SolidHeightfield.SolidHeightFieldIterator dataIterator()
          Provides an iterator that iterates all spans in the field.
 HeightSpan getData(int widthIndex, int depthIndex)
          Gets the lowest span at the grid location, or null if there are no spans at the location.
 boolean hasSpans()
          Indicates whether or not the field contains any spans.
 
Methods inherited from class org.critterai.nmgen.BoundedField
boundsMax, boundsMin, cellHeight, cellSize, depth, getDirOffsetDepth, getDirOffsetWidth, gridIndex, isInBounds, overlaps, resetBounds, resetCellInfo, setBounds, setBounds, setBoundsMax, setBoundsMin, setCellHeight, setCellSize, width
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SolidHeightfield

public SolidHeightfield(float cellSize,
                        float cellHeight)
Constructor

The bounds of the field will default to min(0, 0, 0) and max(1, 1, 1).

Parameters:
cellSize - The size of the cells. (The grid that forms the base of the field.)
cellHeight - The height increment of the field.
Method Detail

addData

public boolean addData(int widthIndex,
                       int depthIndex,
                       int heightIndexMin,
                       int heightIndexMax,
                       int flags)
Adds span data to the heightfield. New span data is either merged into existing spans or a new span is created.

Only the following validations are peformed:

No check that the height maximum is within bounds is performed.

Flags are set as follows:

Basically, only the flags at the top of a span are considered to matter.

Parameters:
widthIndex - The width index of the column that contains the new data.
depthIndex - The depth index of the column that contains the new data.
heightIndexMin - The solid span's minimum. The minimum of the obstructed space. (In zero-based height increments based on BoundedField.cellHeight().)
heightIndexMax - The solid span's maximum. The maximum of the obstructed space. (In zero-based height increments based on BoundedField.cellHeight().)
flags - The flags for the new data.
Returns:
TRUE if the data was successfully added. Otherwise FALSE. The only time this operation will fail is if the argument data is invalid in some way.

dataIterator

public SolidHeightfield.SolidHeightFieldIterator dataIterator()
Provides an iterator that iterates all spans in the field.

Unlike getData(int, int), this iterator will iterate through all spans, not just the base spans. So their is no need to use HeightSpan.next() to climb the span structure.


getData

public HeightSpan getData(int widthIndex,
                          int depthIndex)
Gets the lowest span at the grid location, or null if there are no spans at the location.

The data will be the lowest span at the grid location.

Returns:
The lowest span at the grid location.

hasSpans

public boolean hasSpans()
Indicates whether or not the field contains any spans. If FALSE is returned, then the field does not contain any obstructed space.

Returns:
TRUE if the field contains spans. Otherwise FALSE.


Project Home and Source Code

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