#include <TePatch.h>
This class is used as a representation of the terrain patches database needed by our engine. It also implements the algorithm that computes final patch heihtmap hmap using 4 so-called build maps. This method produces continuous terrain generated from separatedly computed patches.
The class provides scene graph generation too. Using getPatchGraph() and getSeamGraph() methods the landscape can be easily rendered. These methods use caching, so scene graphs are generated only once and are ready to use quickly next time they are needed.
Each patch has to be managed by the TeEngine object and is strongly recommended to use TeEngine::getPatch() method instead of hacking the patch hierarchy in another way.
Public Types | |
enum | Direction { SOUTH_WEST = 0, SOUTH_EAST = 1, NORTH_WEST = 2, NORTH_EAST = 3, SOUTH = 4, WEST = 5, EAST = 6, NORTH = 7 } |
enum | PatchMissedPolicy { DONT_CREATE, CREATE, LOWER_DETAIL } |
enum | WhichHMap { HMAP_PATCH = 4, HMAP_SOUTH_WEST = 0, HMAP_SOUTH_EAST = 1, HMAP_NORTH_WEST = 2, HMAP_NORTH_EAST = 3 } |
Public Member Functions | |
TePatch (TeEngine *engine) | |
~TePatch () | |
const TeHeightMap * | getHMap () const |
TeHeightMap * | getHMap () |
void | setHMap (TeHeightMap *hmap) |
const TeHeightMap * | getSeamMap (const Direction which) const |
TeHeightMap * | getSeamMap (const Direction which) |
void | setSeamMap (const Direction which, TeHeightMap *map) |
SbBool | generateSeamMap (const Direction which) |
TeEngine * | getEngine () const |
void | setEngine () |
const SbBox2f & | getArea () const |
int | getLevel () const |
TePatch * | getParent () const |
TePatch * | getPatch (const SbVec2f &pos, const int level, PatchMissedPolicy policy=CREATE) |
TePatch * | getPatchRelative (const SbVec2f &pos, const int relativeLevel, PatchMissedPolicy policy=CREATE) |
TePatch * | getDetail (const Direction which) |
void | setDetail (const Direction which, TePatch *patch) |
void | removeDetail (TePatch *patch) |
Direction | getDirectionWithinParent () const |
Direction | getDetailDirection (const SbVec2f &point) const |
const TeHeightMap * | getBuildMap (const int i) const |
TeHeightMap * | getBuildMap (const int i) |
void | setBuildMap (const int i, TeHeightMap *hmap) |
void | setBuildMaps (TeHeightMap *nw, TeHeightMap *ne, TeHeightMap *sw, TeHeightMap *se) |
void | findBuildMap (const int i) |
void | prepareBuildMaps () |
void | buildHMapFromBuildMaps () |
void | generateHMapFF (WhichHMap which, const unsigned int seed, const int num_faults, const float min_delta, const float max_delta) |
void | makeRoot (const SbBox2f &area, TeEngine *engine) |
SoSeparator * | getGraph () |
SoSeparator * | getPatchGraph () |
SoSeparator * | getSeamGraph (const Direction which) |
Static Public Member Functions | |
static int | getOppositeDirection (const int d) |
static Direction | getDirectionXFromVec (const SbVec2f &vec) |
Private Member Functions | |
TePatch * | getPatchHierarch (const SbVec2f &pos, const int level, PatchMissedPolicy policy=CREATE) |
TePatch * | getPatchHierarchRelative (const SbVec2f &pos, const int relativeLevel, PatchMissedPolicy policy=CREATE) |
void | updateNeighbours () |
SoSeparator * | generateGraph () |
SoSeparator * | generatePatchGraph () |
SoSeparator * | generateSeamGraph (const Direction which) |
TePatch () | |
Static Private Member Functions | |
static SbVec3f | calculateNormal (const TeHeightMap *map, const int x, const int y, const float sx, const float sy) |
static unsigned short | selectMaterial (float value) |
static SoSeparator * | generateGraphFromSubMap (const TeHeightMap *map, const SbVec2s &min, const SbVec2s &max, const SbBox2f &area) |
Private Attributes | |
SbBox2f | area |
TeHeightMap * | hmap |
TeHeightMap * | seamMap [8] |
TeHeightMap * | buildMap [4] |
TeEngine * | engine |
TePatch * | parent |
TePatch * | detail [4] |
TePatch * | neighbour [8] |
SoSeparator * | graph |
SoSeparator * | seamGraph [8] |
Friends | |
class | TeEngine |
|
Enumerates all 8 possible directions, ASCII-art picture of axis mapping is in the TePatch.h source.
|
|
|
Enumeration used to determine which heightmap should be used at the moment, ASCII-art picture is in the TePatch.h source.
|
|
Simple default constructor. It does not specify the engine that manages this patch and therefore is private and shoul be never called. Documented only to explain the reason. |
|
Constructor.
|
|
Destructor. Releases memory.
|
|
Computes patch height map from four build maps. All build maps have to be set before calling this method.
|
|
Calculates normal at the specified point in the heightmap.
|
|
Tries to find build map by looking in the neighbours. We suppose that correct info is in all of them, therefore we grab the first one. Info propagation is assured by setBuildMap() method. The function returns void, the effect is visible right inside the buildMap attribute.
|
|
Generates "raw" scene graph of the patch. All heightmap values will be used and therefore there won't be gap between patches but visible seam artefacts will be probably over the landscape. Note, that hmap has to be set before calling this function. If it isn't set, empty scene graph is generated. It is recommended to use generatePatchGraph() instead and later fill gaps between paches with seams.
|
|
The function creates scene graph of the specified area of height map given by the map parameter. The parameters min and max specifies the rectangle of the height map that will be used for scene graph generation. The parameter area gives the world-space area that will be occupied by the resulting scene graph. Please note that normal generation algorithm tries to access height map values one point over the rectangle specified by min and max parameters. If these values can not be accessed, the normals are computed without them, but this usually results in artefacts like visible seams between patches.
|
|
Generates heightmap of this patch using fault-formation algorithm. Which height map will be generated is specified by the which parameter. More details about how this algorithm works can be found at TeHeightMap::generate_FaultFormation().
|
|
Generates scene graph of the patch. Not all heightmap values will be used (only those, for that the normal can be computed) and therefore there will be gap between patches that has to be filled with seam. Note, that hmap has to be set before calling this function. If it isn't set, empty scene graph is generated.
|
|
Generates scene graph of the selected seam. If the seam heightmap is not set it tries to generate it, so it is not necessary to call generateSeamMap() before calling this function.
|
|
Validates seamMap pointer in desired direction if possible. Tries to look for the desired map in the neighbours. If not found, tries to compute it and propagate the info to all interested neighbours. This assures that each seam map will be computed only once. User does not need to worry about the way how the data are obtained. This function says if the private seam map pointer is valid or not. Note that properly set hmap attributes of all necessary neighbours are needed to succesfully complete this task.
|
|
Private attribute accessor.
|
|
Private attribute accessor.
|
|
Private attribute accessor.
|
|
Private attribute accessor.
|
|
Documentation not available.
|
|
Documentation not available.
|
|
Computes the direction from the given vector.
|
|
Private attribute accessor.
|
|
High-level "raw" graph request. All heightmap values will be used and therefore there won't be gap between patches but visible seam artefacts will be probably over the landscape. This function does NOT use caching in the TePatch::graph attribute. This rendering mode is obsolete and is recommended to use getPatchGraph() and getSeamGraph() methods instead.
|
|
Private attribute accessor.
|
|
Private attribute accessor.
|
|
Gets level of the patch in the hierarchy.
|
|
Computes opposite direction to the one in d parameter. When called with NORTH as an argument, returns SOUTH, when called with SOUTH_EAST returns NORTH_WEST etc., complies with TePatch::Direction enum values.
|
|
Private attribute accessor.
|
|
Documentation not available.
|
|
High-level graph request. Only those heightmap values, for that we can compute normals will be used, and therefore a gap between patches will occure that has to be filled with seam. The seams may be obtained using getSeamGraph() method. Produced landscape won't have any artefacts along the seam borders then. This function uses caching in the TePatch::graph attribute, so graph is generated only once and is stored for the next time it is needed. Then it will be available very quickly.
|
|
Documentation not available.
|
|
Documentation not available.
|
|
Documentation not available.
|
|
High-level seam graph request. Seams are used to fill gaps between patches that occure because of the normal problem when using getPatchGraph() method. This function uses caching in the TePatch::seamGraph attribute, so graph is generated only once and is stored for the next time it is needed. Then it will be available very quickly. Information about the seam is propagated to all affected neighbours allowing them to share the same data and never do the same work twice.
|
|
Private attribute accessor.
|
|
Private attribute accessor.
|
|
Documentation not available.
|
|
High-level function that prepares all build maps. Tries to find build maps in the neighbours. If map is not found, asks engine to generate new one.
|
|
Documentation not available.
|
|
This function is used to select "colour" of the terrain of given height. This function is for internal use only and uses #defines that can be found right above it in the source code.
|
|
Sets single build map. This function checks whether the resolution of the heightmap hmap correspondes with the one set in the engine. The resolution must be equal to the one returned by TeEngine::getBuildMapResolution() function. If the resolution is incorrect, nothing happens. Info is propagated to all existing neighbours.
|
|
Sets all build maps in a single step. This function simply calls setBuildMap() four times. All restrictions on the heightmaps resolution are therefore applied too.
|
|
Documentation not available.
|
|
Should set the private engine attribute. This function is not implemented yet, it looks like we don't need it...
|
|
Sets private hmap attribute. This function checks if the resolution of the heightmap hmap is the same as the one set in the engine. If it is not so, nothing happens and the warning is post. If there is already some heightmap set, it is deleted.
|
|
Sets private seam map attribute. This function checks if the resolution of the heightmap map corresponds with the one set in the engine and the selected seam. If it is not so, nothing happens and the warning is post.
|
|
Updates local neighbour list and references in that neighbours too.
|
|
Patch area. Defines its rectangle on the surface in the world-space coordinates.
|
|
Pointers to 4 build-maps used to create final heightmap.
|
|
Pointers to the detail patches.
|
|
Pointer to the engine that manages this patch.
|
|
Patch scene graph cache.
|
|
Pointer to the patch height map. This map will be used when creating scene graph.
|
|
Pointers to all 8 possible neighbour of this patch. These are used to obtain seam maps and to find already existing build maps. |
|
Pointer to the parent patch in the patch hierarchy.
|
|
Seam graphs cache.
|
|
Pointers to all 8 possible seam height maps. These maps can be computed when all necessary neighbours' maps are available. These are used when creating seam scene graph.
|