[osg-users] osg::Image::setImage problem

Evan Tsai evanyftsai at gmail.com
Sat Feb 18 13:57:20 PST 2017


Thank you Robert.

Can you point me to more detailed documentation about the definition of these two parameters, packing and rowLength?

Thanks,
Evan



robertosfield wrote:
> HI Evan,
> 
> My best guess is that the packing of the data in each row is out, as
> your Image::setData(..) call doesn't supply all the parameters
> explicitly it will default to a packing of 1 byte.
> 
> For instance if the packing for your source data is 4 bytes, and all
> you previous image data has a width with multiple of 4 then there
> won't be any mismatch when using a 1 byte packing as it will select
> the same width.  However, if you use a width such as 3 then the source
> data with a 4 byte packing would round up to 4 bytes width, but the
> osg::Image::setImage() call you are using says just use 1 byte packing
> so selects a width of 3.  This will result in a each successive row
> starting 1 byte off and leading to the "twist" you see.
> 
> Check the spec of your image reading code/file format to see what the
> row packing is.  Also have a look at the docs for
> osg::Image::setImage(..), note the optional packing and rowLength
> parameters.
> 
> Robert
> 
> 
> 
> 
> 
> 
> On 18 February 2017 at 16:38, Evan Tsai <> wrote:
> 
> > Thank you very much for helping.  Below is how we make the call.
> > 
> > This has been working fine until very recently we received scan data from some CBCT scanners that we haven't encountered before.  However those scans could be viewed correctly in all popular DICOM viewers in the market.  As mentioned, I also took the pixel data and dumped it into a .bmp file, which looks correct.  So the only possibility seems to be that we are missing some setting here......
> > 
> > I did try changing the texture coordinates around but that doesn't change the twisted nature of the display.
> > 
> > I also tried changing `packing' from 1 to 0 but that crashes the software.
> > 
> > Is there anything in particular that one needs to set for `rowLength'?
> > 
> > 
> > 
> > osg::Geode* pGeode = new osg::Geode;
> > 
> > osg::Vec3 v1(pBottomLeft[0], pBottomLeft[1], pBottomLeft[2]);
> > osg::Vec3 v2(pBottomRight[0], pBottomRight[1], pBottomRight[2]);
> > osg::Vec3 v3(pTopRight[0], pTopRight[1], pTopRight[2]);
> > osg::Vec3 v4(pTopLeft[0], pTopLeft[1], pTopLeft[2]);
> > 
> > osg::Geometry* geom = new osg::Geometry;
> > geom->setDataVariance(osg::Object::DYNAMIC);
> > osg::Vec3Array* vertices = new osg::Vec3Array(4);
> > (*vertices)[0] = v1;
> > (*vertices)[1] = v2;
> > (*vertices)[2] = v3;
> > (*vertices)[3] = v4;
> > geom->setVertexArray(vertices);
> > 
> > osg::Vec2Array* texcoords = new osg::Vec2Array(4);
> > (*texcoords)[0].set(0.0f, 0.0f);
> > (*texcoords)[1].set(1, 0.0f);
> > (*texcoords)[2].set(1, 1);
> > (*texcoords)[3].set(0.0f, 1);
> > 
> > geom->setTexCoordArray(0, texcoords);
> > 
> > osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array(1);
> > (*normals)[0].set(0.0f, -1.0f, 0.0f);
> > geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
> > osg::Vec4Array* colors = new osg::Vec4Array(1);
> > (*colors)[0].set(1.0f, 1.0f, 1.0f, 1.0f);
> > geom->setColorArray(colors, osg::Array::BIND_OVERALL);
> > 
> > geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));
> > geom->setUseDisplayList(false);
> > osg::ref_ptr<osg::Image> img = new osg::Image;
> > 
> > img->setImage(image.GetWidth(), image.GetHeight(), 1,
> > GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, image.GetPixelData(),
> > osg::Image::USE_NEW_DELETE);
> > 
> > //osg::ref_ptr<osg::Image> img = osgDB::readRefImageFile("C:\\Users\\rupeshb\\Pictures\\error.bmp");
> > 
> > //osg::ref_ptr<osg::Image> img = osgDB::readRefImageFile(filename);
> > 
> > osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D(img);
> > texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
> > texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
> > osg::ref_ptr<osg::TexMat> texmat = new osg::TexMat;
> > texmat->setScaleByTextureRectangleSize(true);
> > // setup state
> > osg::ref_ptr<osg::StateSet> state = geom->getOrCreateStateSet();
> > state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED);
> > state->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED);
> > 
> > state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
> > 
> > pGeode->addDrawable(geom);
> > addChild(pGeode);
> > 
> > ------------------
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=70254#70254
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > osg-users mailing list
> > 
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > 
> _______________________________________________
> osg-users mailing list
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
>  ------------------
> Post generated by Mail2Forum


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








More information about the osg-users mailing list