osgb是有las文件转换过来的,我采用localspace打开后颜色可以显示,但是采用supermap打开就出现了问题。创建结点的部分代码如下:
osg::Geode *TileToLOD::MakeNodeGeode(const std::vector<PointCI> *pointSet,
std::vector<unsigned int> &pointIndex, ExportMode exportMode)
{
if (pointIndex.size() <= 0)
{
return 0;
}
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> pointArray = new osg::Vec3Array;
osg::ref_ptr<osg::Vec4Array> colorArray = new osg::Vec4Array;
osg::ref_ptr<osg::StateSet> set = new osg::StateSet;
osg::ref_ptr<osg::Point> point = new osg::Point;
//记录点集和颜色集(直接存储的pointCI的点集和颜色集)
for (std::vector<unsigned int>::iterator i = pointIndex.begin(); i != pointIndex.end(); i++)
{
PointCI tmpPoint = pointSet->at(*i);
pointArray->push_back(tmpPoint.P);
if (_colorMode == ColorMode::Debug)
{
colorArray->push_back(_colorBar[0]);
}
else if (_colorMode == ColorMode::RGB)
{
colorArray->push_back(
osg::Vec4(Color8BitsToFloat(tmpPoint.C[0]),
Color8BitsToFloat(tmpPoint.C[1]),
Color8BitsToFloat(tmpPoint.C[2]),
1.f));
}
else if (_colorMode == ColorMode::IntensityGrey)
{
colorArray->push_back(_colorBar[tmpPoint.I]);
}
else if (_colorMode == ColorMode::IntensityBlueWhiteRed)
{
colorArray->push_back(_colorBar[tmpPoint.I]);
}
else if (_colorMode == ColorMode::IntensityHeightBlend)
{
float x = (tmpPoint.P.z() - this->_boundingBoxGlobal.zMin()) / (this->_boundingBoxGlobal.zMax() - this->_boundingBoxGlobal.zMin());
//// sigmoid
//x = (x - 0.5) * 4;
//x = 1. / (1. + exp(-5 * x));
int index = x * 255;
index = std::max(0, std::min(255, index));
osg::Vec4 color = _colorBar[index];
color *= (tmpPoint.I / 255.);
color.w() = 1.0;
colorArray->push_back(color);
}
}
if (_pointSize > 0)
{
//距离衰减
point->setDistanceAttenuation(osg::Vec3(1.0f, 0.0f, 0.01f));
//点大小
point->setSize(_pointSize);
//用于指定图元点的大小和亮度等参数
set->setMode(GL_POINT_SMOOTH, osg::StateAttribute::ON);
//添加点属性
set->setAttribute(point);
geometry->setStateSet(set);
}
//设置顶点
geometry->setVertexArray(pointArray.get());
//设置颜色
geometry->setColorArray(colorArray.get());
//设置颜色的绑定方式为单个顶点
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
//设置顶点的关联方式(此处,为点群的方式)
geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, pointIndex.size()));
//关闭灯光:因为光打开后,顶点颜色就失效了
geometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geode->addDrawable(geometry.get());
return geode.release();
}