osgEarth 2.1.1
|
Public Member Functions | |
ImageToHeightFieldConverter () | |
void | setRemoveNoDataValues (bool value, float fallback=0.0f) |
osg::HeightField * | convert (const osg::Image *image) |
osg::HeightField * | convert (const osg::Image *image, float scaleFactor) |
osg::Image * | convert (const osg::HeightField *hf, int pixelSize=32) |
Private Member Functions | |
osg::HeightField * | convert16 (const osg::Image *image) const |
osg::HeightField * | convert32 (const osg::Image *image) const |
osg::Image * | convert16 (const osg::HeightField *hf) const |
osg::Image * | convert32 (const osg::HeightField *hf) const |
Private Attributes | |
bool | _replace_nodata |
float | _nodata_value |
Utility class that re-interprets an image as a heightfield and vice-versa.
Definition at line 33 of file ImageToHeightFieldConverter.
ImageToHeightFieldConverter::ImageToHeightFieldConverter | ( | ) |
Definition at line 40 of file ImageToHeightFieldConverter.cpp.
: _replace_nodata( false ), _nodata_value( 0.0f ) { //NOP }
osg::HeightField * ImageToHeightFieldConverter::convert | ( | const osg::Image * | image | ) |
Converts an image to a heightfield.
Definition at line 54 of file ImageToHeightFieldConverter.cpp.
{ if ( !image ) { return NULL; } osg::HeightField* hf; if ( image->getPixelSizeInBits() == 32 ) { hf = convert32( image ); } else { hf = convert16( image ); } // scan for and replace NODATA values. This algorithm is terrible but good enough for now if ( _replace_nodata ) { for( unsigned int row=0; row < hf->getNumRows(); ++row ) { for( unsigned int col=0; col < hf->getNumColumns(); ++col ) { float val = hf->getHeight(col, row); if ( !isNoData( val ) ) { continue; } if ( col > 0 ) val = hf->getHeight(col-1,row); else if ( col <= hf->getNumColumns()-1 ) val = hf->getHeight(col+1,row); if ( isNoData( val ) ) { if ( row > 0 ) val = hf->getHeight(col, row-1); else if ( row < hf->getNumRows()-1 ) val = hf->getHeight(col, row+1); } if ( isNoData( val ) ) { val = _nodata_value; } hf->setHeight( col, row, val ); } } } return hf; }
osg::Image * ImageToHeightFieldConverter::convert | ( | const osg::HeightField * | hf, |
int | pixelSize = 32 |
||
) |
Converts a heightfield to an image.
Definition at line 153 of file ImageToHeightFieldConverter.cpp.
osg::HeightField * ImageToHeightFieldConverter::convert | ( | const osg::Image * | image, |
float | scaleFactor | ||
) |
Definition at line 135 of file ImageToHeightFieldConverter.cpp.
{ if ( !image ) { return NULL; } osg::HeightField* hf = convert( image ); // finally, apply the scale factor. for( osg::FloatArray::iterator i = hf->getFloatArray()->begin(); i != hf->getFloatArray()->end(); ++i ) { (*i) *= scaleFactor; } return hf; }
osg::HeightField * ImageToHeightFieldConverter::convert16 | ( | const osg::Image * | image | ) | const [private] |
Definition at line 103 of file ImageToHeightFieldConverter.cpp.
{ if ( !image ) { return NULL; } osg::HeightField *hf = new osg::HeightField(); hf->allocate( image->s(), image->t() ); osg::FloatArray* floats = hf->getFloatArray(); for( unsigned int i = 0; i < floats->size(); ++i ) { floats->at( i ) = *(short*)image->data(i); } return hf; }
osg::Image * ImageToHeightFieldConverter::convert16 | ( | const osg::HeightField * | hf | ) | const [private] |
Definition at line 162 of file ImageToHeightFieldConverter.cpp.
{ if ( !hf ) { return NULL; } osg::Image* image = new osg::Image(); image->allocateImage(hf->getNumColumns(), hf->getNumRows(), 1, GL_LUMINANCE, GL_SHORT); const osg::FloatArray* floats = hf->getFloatArray(); for( unsigned int i = 0; i < floats->size(); ++i ) { *(short*)image->data(i) = (short)floats->at( i ); } return image; }
osg::Image * ImageToHeightFieldConverter::convert32 | ( | const osg::HeightField * | hf | ) | const [private] |
Definition at line 179 of file ImageToHeightFieldConverter.cpp.
{ if ( !hf ) { return NULL; } osg::Image* image = new osg::Image(); image->allocateImage(hf->getNumColumns(), hf->getNumRows(), 1, GL_LUMINANCE, GL_FLOAT); memcpy( image->data(), &hf->getFloatArray()->front(), sizeof(float) * hf->getFloatArray()->size() ); return image; }
osg::HeightField * ImageToHeightFieldConverter::convert32 | ( | const osg::Image * | image | ) | const [private] |
Definition at line 120 of file ImageToHeightFieldConverter.cpp.
{ if ( !image ) { return NULL; } osg::HeightField *hf = new osg::HeightField(); hf->allocate( image->s(), image->t() ); memcpy( &hf->getFloatArray()->front(), image->data(), sizeof(float) * hf->getFloatArray()->size() ); return hf; }
void ImageToHeightFieldConverter::setRemoveNoDataValues | ( | bool | value, |
float | fallback = 0.0f |
||
) |
Instruct the converter to detect and replace "no data" values. It will try to interpolate the proper value, or fall back on the provided value if the interpolation fails.
Definition at line 48 of file ImageToHeightFieldConverter.cpp.
{ _nodata_value = f; _replace_nodata = which; }
float osgEarth::ImageToHeightFieldConverter::_nodata_value [private] |
Definition at line 65 of file ImageToHeightFieldConverter.
bool osgEarth::ImageToHeightFieldConverter::_replace_nodata [private] |
Definition at line 64 of file ImageToHeightFieldConverter.