[osg-users] Geometry vertices and nan/inf

105 views
Skip to first unread message

Erik Hensens

unread,
Mar 14, 2015, 11:06:21 AM3/14/15
to osg-...@lists.openscenegraph.org
Hello all,

I'm analyzing the vertices of a geometry like so:


Code:

osg::Array *pVertexArray = pGeometry->getVertexArray();
int nVertices = (int)(pVertexArray->getNumElements());
osg::Vec3 *pVertexData = (osg::Vec3 *)(pVertexArray->getDataPointer());
for (int i = 0; i < nVertices; i++)
{
float fVertexX = (pVertexData + i)->x();
float fVertexY = (pVertexData + i)->y();
float fVertexZ = (pVertexData + i)->z();
...
}




And sometimes these vertex x(), y(), and/or z() parameters are nan or inf. Am I doing something wrong? I don't understand how this would happen.

Thanks a bunch!

Cheers,
Erik

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





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Mar 14, 2015, 11:46:27 AM3/14/15
to OpenSceneGraph Users
Hi Erik,

Your code is rather perverse and potentially unsafe way to get at the xyz coords, but if the array is a Vec3Array then it should probably work OK.

A better way to look at to coords is to cast the array to a Vec3Array and access the vertices via the std::vector<> methods (Vec3Array subclasses from std::vector<>) i.e.

  osg::Vec3Array* vertices  = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray());
  if (vetices)
  {
       for(unsigned int i=0; i<vertices->size(); ++i)
       {
             osg::Vec3& vertex = (*vertices)[i];
             std::cout<<"x="<<vertex.x()<<", y="<<vertex.y()<<", "<<vertex.z()<<std::endl;  
       }
  }

Robert.

Erik Hensens

unread,
Mar 16, 2015, 12:44:32 PM3/16/15
to osg-...@lists.openscenegraph.org

robertosfield wrote:
> Your code is rather perverse and potentially unsafe way to get at the xyz coords, but if the array is a Vec3Array then it should probably work OK.
>
>
> A better way to look at to coords is to cast the array to a Vec3Array and access the vertices via the std::vector<> methods (Vec3Array subclasses from std::vector<>) i.e.
>
>
>   osg::Vec3Array* vertices  = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray());
>   if (vetices)
>   {
>        for(unsigned int i=0; i<vertices->size(); ++i)
>        {
>              osg::Vec3& vertex = (*vertices)[i];
>              std::cout<<"x="<<vertex.x()<<", y="<<vertex.y()<<", "<<vertex.z()<<std::endl;  
>        }
>   }
>
>
> Robert.
>


Hi Robert,

Thank you very much for your response. I don't understand how my code was potentially unsafe. Getting the type via pVertexArray->getType() returns Vec3ArrayType, shouldn't all Geometry vertex arrays be of this type?

As per my original question about non-real floating point coordinates, I believe I may be to blame; I might have accidentally set some non-real values as vertex x, y, and/or z values when building the Geometry in the first place. I am currently working on verifying whether or not this is so.

I suppose what surprised me was that OSG was able to draw the Geode that used the Geometry with the occasional nan/+inf/-inf vertex x/y/z parameter without any issues.

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=63111#63111

Reply all
Reply to author
Forward
0 new messages