Dear List,

I want to render a point cloud (say from a 3D scanner). I use the
following code:

(pc is a PointCloud which contains three vectors of floats, aScene is a
osg::Group)

---------------------------------------------------------------
osg::PositionAttitudeTransform* trans = new
osg::PositionAttitudeTransform();
osg::Geometry* geo = new osg::Geometry;
osg::Geode* node = new osg::Geode;

node->addDrawable( geo );
trans->addChild( node );

trans->setPosition( osg::Vec3d( x, y, z ) );
trans->setAttitude( osg::Quat( yaw, osg::Vec3d(0,0,1), pitch,
osg::Vec3d(0,1,0), roll, osg::Vec3d(1,0,0) ) );

const vector<float>& vx = pc.getX();
const vector<float>& vy = pc.getY();
const vector<float>& vz = pc.getZ();

osg::Vec3Array* points = new osg::Vec3Array;
for( unsigned int i=0; i < vx.size(); i++ ) {
        points->push_back( osg::Vec3( vx[i], vy[i], vz[i] ) );
}
geo->setVertexArray( points );

osg::DrawElementsUInt* draw = new
osg::DrawElementsUInt(osg::PrimitiveSet::POINTS, 0);
for( unsigned int i=0; i < vx.size(); i++ ) {
        draw->push_back( i );
}
geo->addPrimitiveSet( draw );

osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) );

geo->setColorArray(colors);
geo->setColorBinding(osg::Geometry::BIND_OVERALL);

aScene->addChild( trans );
---------------------------------------------------------------

It works, but for some reason, the points seem to be less visible from
some directions than from others (i.e. I see them from the front but not
from the back). Is this by design? How do I make sure the points can be
seen from all sides?

Thanks for the help!
Max Pfingsthorn
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to