本文整理汇总了C++中osg::ref_ptr::allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ ref_ptr::allocate方法的具体用法?C++ ref_ptr::allocate怎么用?C++ ref_ptr::allocate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::ref_ptr
的用法示例。
在下文中一共展示了ref_ptr::allocate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: creation_terrain
osg::Node* creation_terrain(){
osg::Image* heightMap = osgDB::readImageFile("terrain.tga");
osg::HeightField* terrain = new osg::HeightField();
terrain->allocate(heightMap->s(), heightMap->t());
terrain->setOrigin(osg::Vec3(-heightMap->s() / 2, -heightMap->t() / 2, 0));
terrain->setXInterval(10.0f);
terrain->setYInterval(10.0f);
for (unsigned int r = 0; r < terrain->getNumRows(); r++)
for (unsigned int c = 0; c < terrain->getNumColumns(); c++)
terrain->setHeight(c, r, ((*heightMap->data(c, r)) / 255.0f) * 300.0f);
osg::Geode* geode = new osg::Geode();
geode->addDrawable(new osg::ShapeDrawable(terrain));
osg::Material* mat = new osg::Material;
mat->setAmbient (osg::Material::FRONT_AND_BACK, osg::Vec4(0.5, 0.5, 0.5, 1.0));
mat->setDiffuse (osg::Material::FRONT_AND_BACK, osg::Vec4(0.9, 0.9, 0.9, 1.0));
mat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0, 0.0, 0.0, 1.0));
mat->setShininess(osg::Material::FRONT_AND_BACK, 64);
geode->getOrCreateStateSet()->setAttributeAndModes(mat);
osg::Texture2D* tex = new osg::Texture2D(osgDB::readImageFile("herbe.tga"));
tex->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_LINEAR);
tex->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
tex->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex);
osg::Matrixd matrix;
matrix.makeScale(osg::Vec3(10, 10, 1.0));
osg::ref_ptr<osg::TexMat> matTexture = new osg::TexMat;
matTexture->setMatrix(matrix);
geode->getOrCreateStateSet()->setTextureAttributeAndModes(0,
matTexture.get(), osg::StateAttribute::ON);
return geode;
}
示例2: getProfile
void
ElevationLayer::assembleHeightField(const TileKey& key,
osg::ref_ptr<osg::HeightField>& out_hf,
osg::ref_ptr<NormalMap>& out_normalMap,
ProgressCallback* progress)
{
// Collect the heightfields for each of the intersecting tiles.
GeoHeightFieldVector heightFields;
//Determine the intersecting keys
std::vector< TileKey > intersectingTiles;
if (key.getLOD() > 0u)
{
getProfile()->getIntersectingTiles(key, intersectingTiles);
}
else
{
// LOD is zero - check whether the LOD mapping went out of range, and if so,
// fall back until we get valid tiles. This can happen when you have two
// profiles with very different tile schemes, and the "equivalent LOD"
// surpasses the max data LOD of the tile source.
unsigned numTilesThatMayHaveData = 0u;
int intersectionLOD = getProfile()->getEquivalentLOD(key.getProfile(), key.getLOD());
while (numTilesThatMayHaveData == 0u && intersectionLOD >= 0)
{
intersectingTiles.clear();
getProfile()->getIntersectingTiles(key.getExtent(), intersectionLOD, intersectingTiles);
for (unsigned int i = 0; i < intersectingTiles.size(); ++i)
{
const TileKey& layerKey = intersectingTiles[i];
if (mayHaveData(layerKey) == true)
{
++numTilesThatMayHaveData;
}
}
--intersectionLOD;
}
}
// collect heightfield for each intersecting key. Note, we're hitting the
// underlying tile source here, so there's no vetical datum shifts happening yet.
// we will do that later.
if ( intersectingTiles.size() > 0 )
{
for (unsigned int i = 0; i < intersectingTiles.size(); ++i)
{
const TileKey& layerKey = intersectingTiles[i];
if ( isKeyInLegalRange(layerKey) )
{
osg::ref_ptr<osg::HeightField> hf;
osg::ref_ptr<NormalMap> normalMap;
createImplementation(layerKey, hf, normalMap, progress);
if (hf.valid())
{
heightFields.push_back( GeoHeightField(hf.get(), normalMap.get(), layerKey.getExtent()) );
}
}
}
// If we actually got a HeightField, resample/reproject it to match the incoming TileKey's extents.
if (heightFields.size() > 0)
{
unsigned int width = 0;
unsigned int height = 0;
for (GeoHeightFieldVector::iterator itr = heightFields.begin(); itr != heightFields.end(); ++itr)
{
if (itr->getHeightField()->getNumColumns() > width)
width = itr->getHeightField()->getNumColumns();
if (itr->getHeightField()->getNumRows() > height)
height = itr->getHeightField()->getNumRows();
}
//Now sort the heightfields by resolution to make sure we're sampling the highest resolution one first.
std::sort( heightFields.begin(), heightFields.end(), GeoHeightField::SortByResolutionFunctor());
out_hf = new osg::HeightField();
out_hf->allocate(width, height);
out_normalMap = new NormalMap(width, height);
//Go ahead and set up the heightfield so we don't have to worry about it later
double minx, miny, maxx, maxy;
key.getExtent().getBounds(minx, miny, maxx, maxy);
double dx = (maxx - minx)/(double)(width-1);
double dy = (maxy - miny)/(double)(height-1);
//Create the new heightfield by sampling all of them.
for (unsigned int c = 0; c < width; ++c)
{
double x = minx + (dx * (double)c);
for (unsigned r = 0; r < height; ++r)
{
//.........这里部分代码省略.........
示例3: if
//.........这里部分代码省略.........
return false;
}
}
else if (heightFields.size() == 1)
{
if ( lowestLOD == key.getLevelOfDetail() )
{
//If we only have on heightfield, just return it.
out_result = heightFields[0].takeHeightField();
}
else
{
GeoHeightField geoHF = heightFields[0].createSubSample( key.getExtent(), interpolation);
out_result = geoHF.takeHeightField();
hfInitialized = true;
}
}
else
{
//If we have multiple heightfields, we need to composite them together.
unsigned int width = 0;
unsigned int height = 0;
for (GeoHeightFieldVector::const_iterator i = heightFields.begin(); i < heightFields.end(); ++i)
{
if (i->getHeightField()->getNumColumns() > width)
width = i->getHeightField()->getNumColumns();
if (i->getHeightField()->getNumRows() > height)
height = i->getHeightField()->getNumRows();
}
out_result = new osg::HeightField();
out_result->allocate( width, height );
//Go ahead and set up the heightfield so we don't have to worry about it later
double minx, miny, maxx, maxy;
key.getExtent().getBounds(minx, miny, maxx, maxy);
double dx = (maxx - minx)/(double)(out_result->getNumColumns()-1);
double dy = (maxy - miny)/(double)(out_result->getNumRows()-1);
const SpatialReference* keySRS = keyToUse.getProfile()->getSRS();
//Create the new heightfield by sampling all of them.
for (unsigned int c = 0; c < width; ++c)
{
double x = minx + (dx * (double)c);
for (unsigned r = 0; r < height; ++r)
{
double y = miny + (dy * (double)r);
//Collect elevations from all of the layers. Iterate BACKWARDS because the last layer
// is the highest priority.
std::vector<float> elevations;
for( GeoHeightFieldVector::reverse_iterator itr = heightFields.rbegin(); itr != heightFields.rend(); ++itr )
{
const GeoHeightField& geoHF = *itr;
float elevation = 0.0f;
if ( geoHF.getElevation(keySRS, x, y, interpolation, keySRS, elevation) )
{
if (elevation != NO_DATA_VALUE)
{
elevations.push_back(elevation);
}
}