WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-14-2010, 02:15 PM
Renato Lima Renato Lima is offline
Member
 
Join Date: Sep 2010
Posts: 54
Question Pylab, StringIO and viz.add

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
Reply With Quote
  #2  
Old 09-14-2010, 03:07 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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:
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)
Reply With Quote
  #3  
Old 09-14-2010, 05:40 PM
Renato Lima Renato Lima is offline
Member
 
Join Date: Sep 2010
Posts: 54
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.
Reply With Quote
  #4  
Old 10-12-2010, 11:11 AM
Renato Lima Renato Lima is offline
Member
 
Join Date: Sep 2010
Posts: 54
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?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 10:32 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC