Re: [osg-users] Reading/Writing osg::Image data [SEC=UNCLASSIFIED]
Thanks Ulrich, I eventually got it going, posting for reference: Size I allocated was the issue. Regards Reading: === unsigned char* data = new unsigned char[texSize*texSize*texSize*4]; std::ifstream fin(filename.c_str(),std::ios::in | std::ios::binary); fin.read((char*)data ,(texSize*texSize*texSize*4)); fin.close(); osg::ref_ptr image = new osg::Image; image->setImage(texSize, texSize, texSize,4, GL_RGBA, L_UNSIGNED_BYTE,data,osg::Image::USE_NEW_DELETE); Writing: = std::ofstream fout ("data/textures/image3d/imagedata3d_128",std::ios::app | std::ios::out | std::ios::binary); unsigned int size = image->getTotalSizeInBytesIncludingMipmaps(); fout.write( (char*)image->data(), size ); // Check if ( fout.fail() ) std::cout<<"Failed to write image->data"< Hi Paul, > > On 23/06/10 11:53 , Paul Pocock wrote: > >> I'm trying to write 3d texture data to file but when loading back into >> osg::Image I'm getting rubbish: >> >> Writing to file with 3d texture data: >> >> unsigned int size = image->getTotalSizeInBytesIncludingMipmaps(); >> fout.write( (char*)image->data(), size ); >> >> >> Reading from file: >> >> unsigned char* data = new unsigned char[texSize*texSize*texSize*4]; >> std::ifstream fin("image3ddata2",std::ios::binary); >> >> fin.read((char*)&data ,(sizeof(unsigned char)* 4 * texSize * texSize * >> texSize)); >> >> osg::ref_ptr image = new osg::Image; >> image->setImage(texSize,texSize,texSize,4, GL_RGBA, >> GL_UNSIGNED_BYTE,data, osg::Image::USE_NEW_DELETE); >> >> >> Can anyone see anything I'm doing wrong? Either Writing or Reading? >> > I cannot spot anything obviously wrong with the code. > Can you check if the file on disk is okay, so that either part (writing or > reading) can be > ruled out? > > I'd also try to set the memory to some pattern before reading, in case the > file isn't > fully read or something. > > Cheers, > /ulrich > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > IMPORTANT: This email remains the property of the Department of Defence and is subject to the jurisdiction of section 70 of the Crimes Act 1914. If you have received this email in error, you are requested to contact the sender and delete the email. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Reading/Writing osg::Image data [SEC=UNCLASSIFIED]
Hi Paul, On 23/06/10 11:53 , Paul Pocock wrote: > I'm trying to write 3d texture data to file but when loading back into > osg::Image I'm getting rubbish: > > Writing to file with 3d texture data: > > unsigned int size = image->getTotalSizeInBytesIncludingMipmaps(); > fout.write( (char*)image->data(), size ); > > > Reading from file: > > unsigned char* data = new unsigned char[texSize*texSize*texSize*4]; > std::ifstream fin("image3ddata2",std::ios::binary); > > fin.read((char*)&data ,(sizeof(unsigned char)* 4 * texSize * texSize * > texSize)); > > osg::ref_ptr image = new osg::Image; > image->setImage(texSize,texSize,texSize,4, GL_RGBA, > GL_UNSIGNED_BYTE,data, osg::Image::USE_NEW_DELETE); > > > Can anyone see anything I'm doing wrong? Either Writing or Reading? I cannot spot anything obviously wrong with the code. Can you check if the file on disk is okay, so that either part (writing or reading) can be ruled out? I'd also try to set the memory to some pattern before reading, in case the file isn't fully read or something. Cheers, /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Reading/Writing osg::Image data [SEC=UNCLASSIFIED]
Hi All, I'm trying to write 3d texture data to file but when loading back into osg::Image I'm getting rubbish: Writing to file with 3d texture data: unsigned int size = image->getTotalSizeInBytesIncludingMipmaps(); fout.write( (char*)image->data(), size ); Reading from file: unsigned char* data = new unsigned char[texSize*texSize*texSize*4]; std::ifstream fin("image3ddata2",std::ios::binary); fin.read((char*)&data ,(sizeof(unsigned char)* 4 * texSize * texSize * texSize)); osg::ref_ptr image = new osg::Image; image->setImage(texSize,texSize,texSize,4, GL_RGBA, GL_UNSIGNED_BYTE,data, osg::Image::USE_NEW_DELETE); Can anyone see anything I'm doing wrong? Either Writing or Reading? Best Regards Paul IMPORTANT: This email remains the property of the Department of Defence and is subject to the jurisdiction of section 70 of the Crimes Act 1914. If you have received this email in error, you are requested to contact the sender and delete the email. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org