NL3D::CHeightMap Class Reference

#include <height_map.h>


Detailed Description

A HeightMap. The heightMap is oriented left-right(X+) / bottom-top(Y+).
Author:
Lionel Berenguier

Nevrax France

Date:
2001

Definition at line 46 of file height_map.h.

Public Member Functions

void buildFromBitmap (const NLMISC::CBitmap &bitmap)
 CHeightMap ()
 Constructor.

uint getHeight () const
uint getWidth () const
float getZ (uint x, uint y) const
 return the ZValue, interval is: 0-MaxZ. nlassert(x,y).

void resize (uint w, uint h)
 resize the heightmap. resize Heights too.


Data Fields

std::vector< uint8Heights
float MaxZ
 The range of heights: 0 to MaxZ.

float OriginX
 The origin of the bottom-left corner of this heightmap.

float OriginY
 The origin of the bottom-left corner of this heightmap.

float SizeX
 The size of one Element ot this HeightMap (eg: 160x160 for a zone).

float SizeY
 The size of one Element ot this HeightMap (eg: 160x160 for a zone).


Private Attributes

uint _Height
 The size of this array. Heights.size.

uint _Width
 The size of this array. Heights.size.


Constructor & Destructor Documentation

NL3D::CHeightMap::CHeightMap  )  [inline]
 

Constructor.

Definition at line 60 of file height_map.h.

References MaxZ, and NL3D_MEM_HMAP.

00061         {
00062                 NL3D_MEM_HMAP
00063                 SizeX= SizeY= 160;
00064                 OriginX= OriginY= 0;
00065                 MaxZ= 100;
00066         }


Member Function Documentation

void NL3D::CHeightMap::buildFromBitmap const NLMISC::CBitmap bitmap  ) 
 

This tool method build a HeightMap, from a bitmap, resize(), and fill Heights. value are read from bitmap luminance value. NB: Lines are inverted, because bitmap definition is left-right / top-bottom.

Definition at line 49 of file height_map.cpp.

References NLMISC::CBitmap::convertToType(), Heights, NL3D_MEM_HMAP, resize(), uint, uint8, v, w, x, and y.

00050 {
00051         NL3D_MEM_HMAP
00052         // copy bitmap.
00053         CBitmap         bitmap= bitmap0;
00054         // convert to luminance.
00055         bitmap.convertToType(CBitmap::Luminance);
00056 
00057         // resize array.
00058         uint    w, h;
00059         w= bitmap.getWidth();
00060         h= bitmap.getHeight();
00061         resize(w,h);
00062 
00063         // get luminance image.
00064         CObjectVector<uint8>    &array= bitmap.getPixels();
00065         // invert the image in Y.
00066         for(uint y=0;y<h;y++)
00067         {
00068                 for(uint x=0;x<w;x++)
00069                 {
00070                         uint8   v= array[(h-1-y)*w+x];
00071                         Heights[y*w+x]= v;
00072                 }
00073         }
00074 }

uint NL3D::CHeightMap::getHeight  )  const [inline]
 

Definition at line 72 of file height_map.h.

References uint.

Referenced by NL3D::CLandscape::setHeightField().

00072 {return _Height;}

uint NL3D::CHeightMap::getWidth  )  const [inline]
 

Definition at line 71 of file height_map.h.

References uint.

Referenced by NL3D::CLandscape::setHeightField().

00071 {return _Width;}

float NL3D::CHeightMap::getZ uint  x,
uint  y
const
 

return the ZValue, interval is: 0-MaxZ. nlassert(x,y).

Definition at line 78 of file height_map.cpp.

References Heights, MaxZ, NL3D_MEM_HMAP, nlassert, uint, x, and y.

Referenced by NL3D::CLandscape::setHeightField().

00079 {
00080         NL3D_MEM_HMAP
00081         nlassert(x<_Width && y<_Height);
00082         return Heights[y*_Width+x]*MaxZ/255;
00083 }

void NL3D::CHeightMap::resize uint  w,
uint  h
 

resize the heightmap. resize Heights too.

Definition at line 39 of file height_map.cpp.

References Heights, NL3D_MEM_HMAP, uint, and w.

Referenced by buildFromBitmap().

00040 {
00041         NL3D_MEM_HMAP
00042         _Width= w;
00043         _Height= h;
00044         Heights.resize(w*h);
00045 }


Field Documentation

uint NL3D::CHeightMap::_Height [private]
 

The size of this array. Heights.size.

Definition at line 86 of file height_map.h.

uint NL3D::CHeightMap::_Width [private]
 

The size of this array. Heights.size.

Definition at line 86 of file height_map.h.

std::vector<uint8> NL3D::CHeightMap::Heights
 

Definition at line 49 of file height_map.h.

Referenced by buildFromBitmap(), getZ(), and resize().

float NL3D::CHeightMap::MaxZ
 

The range of heights: 0 to MaxZ.

Definition at line 56 of file height_map.h.

Referenced by CHeightMap(), and getZ().

float NL3D::CHeightMap::OriginX
 

The origin of the bottom-left corner of this heightmap.

Definition at line 52 of file height_map.h.

Referenced by NL3D::CLandscape::setHeightField().

float NL3D::CHeightMap::OriginY
 

The origin of the bottom-left corner of this heightmap.

Definition at line 52 of file height_map.h.

Referenced by NL3D::CLandscape::setHeightField().

float NL3D::CHeightMap::SizeX
 

The size of one Element ot this HeightMap (eg: 160x160 for a zone).

Definition at line 54 of file height_map.h.

Referenced by NL3D::CLandscape::setHeightField().

float NL3D::CHeightMap::SizeY
 

The size of one Element ot this HeightMap (eg: 160x160 for a zone).

Definition at line 54 of file height_map.h.

Referenced by NL3D::CLandscape::setHeightField().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:47:05 2004 for NeL by doxygen 1.3.6