PDA

View Full Version : Pylab, StringIO and viz.add


Renato Lima
09-14-2010, 02:15 PM
I have been trying to generate some charts on the fly and then apply them as textures to objects. However, viz.add triggers the following message when I try to add an image that has been saved to memory:

File "C:\Program Files (x86)\WorldViz\Vizard30/python\viz.py", line 8704, in add raise ValueError, 'Unrecognized file extension: '+fileType


This is my code:

t = pylab.arange(0.0, 2.0, 0.01)
s = pylab.sin(2*pylab.pi*t)
pylab.plot(t, s, linewidth=1.0)
pylab.xlabel('supertime (s)')
pylab.ylabel('voltage (mV)')

savemem = StringIO.StringIO()

pylab.savefig(imgData, format='png' )
pylab.close()
texturetoapply = viz.add(imgData.read)


Is it a limitation of vizard? or am I doing something wrong? I really don't want to save the file to the disk as it greatly reduces performance.

Thanks

farshizzo
09-14-2010, 03:07 PM
The texture objects have a few functions for loading images from memory.

<texture>.setImageData allows you to set the raw RGB data of an image. This is the most efficient method.

If the data is from an image format that is in memory (png, jpeg, bmp, etc..), then you can use <texture>.loadBuffer.

Here is some sample code:
# Create a blank texture that will be updated later
tex = viz.addBlankTexture([1,1])

# Set image from raw rgb data that is 256 x 256
tex.setImageData(rgbData,[256,256],viz.TEX_RGB)

# Set image from png image data in memory
tex.loadBuffer('.png',pngData)

Renato Lima
09-14-2010, 05:40 PM
It worked nicely!
Thank you very much for your quick reply. Your fast support is really driving us towards adopting Vizard as one of our main platforms for development.

Renato Lima
10-12-2010, 11:11 AM
In fact, after using this for a while, I realized that que quality of the texture is much inferior than what I obtain by using a real image. Any ideas?