Hi all,

I am trying to display a point cloud in osg and having some problems. I display 
the same dataset in an OpenGL based application and it works fine. But when I 
display it in osg I just see all the points displayed across a line.


Here is my code for converting the points stored in 

vector<Pt> m_list;

where Pt has three float and 3 unsigned integers for storing color value of 
each point.


Code:

        osg::Geode * formPointCloud()
        {
                osg::Geode* cloudGeode = new osg::Geode();
                osg::Geometry* cloudGeometry = new osg::Geometry();  

                osg::Vec4Array* cloudVertices = new osg::Vec4Array;

                for ( int i = 0 ; i < m_list.size() ; i++ )
                        cloudVertices->push_back( osg::Vec4d(m_list[i].fX, 
m_list[i].fY, m_list[i].fZ, 1.0f) );

                cloudGeometry->setVertexArray( cloudVertices );

                cloudGeometry->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, m_list.size()));


                osg::Vec4Array* colors = new osg::Vec4Array;
                for ( int i = 0 ; i < m_list.size() ; i++ )
                        colors->push_back(osg::Vec4f (m_list[i].uR/255.0f, 
m_list[i].uG/255.0f, m_list[i].uB/255.0f, 1.0f) );

                osg::TemplateIndexArray
                        <unsigned int, osg::Array::UIntArrayType,4,4> 
*colorIndexArray;
                colorIndexArray = new osg::TemplateIndexArray<unsigned int, 
osg::Array::UIntArrayType,4,4>;
                for ( int i = 0 ; i < m_list.size() ; i++ )
                        colorIndexArray->push_back(i);

                cloudGeometry->setColorArray(colors);
                cloudGeometry->setColorIndices(colorIndexArray);
                cloudGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);

                cloudGeode->addDrawable(cloudGeometry); 

                return cloudGeode;
        }

   
       //////////// the code in the main is ////////////////////


        PointCloud ptcloud;
        ptcloud.readPointCloud(str);
        osg::Geode * ptrCloudGeode = ptcloud.formPointCloud();

        root->addChild(ptrCloudGeode);

        viewer.setSceneData( root );
     ///////////////////////////////////////////////////////////




I would really appreciate if someone could help me with this.

Thanks,
Omar

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=7378#7378





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to