3D Graphics .clear()

1,236 views
Skip to first unread message

Mathew Schwartz

unread,
Apr 22, 2013, 1:26:08 AM4/22/13
to pyqt...@googlegroups.com
I was wondering if there is a way to clear the 3d graphics view like the plot option.  I was wondering if there is either a reset for the entire gl view, or if there is a way to clear a specific item.  My goal is to have a grid drawn, then place some object, then be able to remove the object without changing the grid.  

Thanks

Mat

Luke Campagnola

unread,
Apr 22, 2013, 7:51:58 AM4/22/13
to pyqt...@googlegroups.com
On Mon, Apr 22, 2013 at 1:26 AM, Mathew Schwartz <umc...@gmail.com> wrote:
I was wondering if there is a way to clear the 3d graphics view like the plot option.  I was wondering if there is either a reset for the entire gl view, or if there is a way to clear a specific item.  My goal is to have a grid drawn, then place some object, then be able to remove the object without changing the grid.  


There is GLViewWidget.removeItem( item ).  
Sorry; I see this hasn't been documented yet. If you run 'help(GLViewWidget)' from an interactive prompt, you can see all of the method names, including the ones I haven't documented.


Luke
 

Mathew Schwartz

unread,
Apr 23, 2013, 3:48:53 AM4/23/13
to pyqt...@googlegroups.com
Thanks!  I was having some trouble so I hadnt responded but I figured out what i was doing wrong.  I do have another question though.  I was able to use the grabFrameBuffer() to get my image, however the pixMap gives me this error 



--
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
---
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mathew Schwartz

unread,
Apr 23, 2013, 3:49:57 AM4/23/13
to pyqt...@googlegroups.com
sorry this is the error: 

    |==============================>>

| Traceback (most recent call last):

| File "C:/Python26/Lib/site-packages/pyqtgraph\opengl\GLViewWidget.py", line 115, in drawItemTree

| i.paint()

| File "C:/Python26/Lib/site-packages/pyqtgraph\opengl\items\GLScatterPlotItem.py", line 101, in paint

| glEnable(GL_POINT_SPRITE)

| File "errorchecker.pyx", line 50, in OpenGL_accelerate.errorchecker._ErrorChecker.glCheckError (src\errorchecker.c:854)

| GLError: GLError(

| err = 1280,

| description = 'invalid enumerant',

| baseOperation = glEnable,

| cArguments = (GL_POINT_SPRITE,)

| )

|

|==============================<<

Error while drawing item <pyqtgraph.opengl.items.GLScatterPlotItem.GLScatterPlotItem object at 0x40619C90>. The original exception is printed above; however, pyqtgraph requires OpenGL version 2.0 or greater for many of its 3D features and your OpenGL version is 1.1.0. Installing updated display drivers may resolve this issue.


Do you know if this is actually an OpenGL version problem or is something else wrong


Thanks!

Mathew Schwartz

unread,
Apr 23, 2013, 3:58:18 AM4/23/13
to pyqt...@googlegroups.com
Also maybe i should mention, if i dont have any objects drawn, but i draw the grid, i dont get the error and the grid renders to image.  If i have objects i get the error, but it still renders the grid just with none of the scatter dots.  

Luke Campagnola

unread,
Apr 23, 2013, 7:42:49 AM4/23/13
to pyqt...@googlegroups.com
On Tue, Apr 23, 2013 at 3:49 AM, Mathew Schwartz <umc...@gmail.com> wrote:
sorry this is the error: 

    |==============================>>

| Traceback (most recent call last):

| File "C:/Python26/Lib/site-packages/pyqtgraph\opengl\GLViewWidget.py", line 115, in drawItemTree

| i.paint()

| File "C:/Python26/Lib/site-packages/pyqtgraph\opengl\items\GLScatterPlotItem.py", line 101, in paint

| glEnable(GL_POINT_SPRITE)

| File "errorchecker.pyx", line 50, in OpenGL_accelerate.errorchecker._ErrorChecker.glCheckError (src\errorchecker.c:854)

| GLError: GLError(

| err = 1280,

| description = 'invalid enumerant',

| baseOperation = glEnable,

| cArguments = (GL_POINT_SPRITE,)

| )

|

|==============================<<

Error while drawing item <pyqtgraph.opengl.items.GLScatterPlotItem.GLScatterPlotItem object at 0x40619C90>. The original exception is printed above; however, pyqtgraph requires OpenGL version 2.0 or greater for many of its 3D features and your OpenGL version is 1.1.0. Installing updated display drivers may resolve this issue.


Do you know if this is actually an OpenGL version problem or is something else wrong

 
 
Point sprites were introduced in OpenGL 1.5. I would recommend upgrading if possible.

Luke


 

Mathew Schwartz

unread,
Apr 24, 2013, 9:28:22 PM4/24/13
to pyqt...@googlegroups.com
Hi Luke,

I have tested this on two computers, one with i3 integrated graphics, the other with i7 geforce gt 630M, the latter has opengl 4.2.    I attached an example file, its your scatter plot example and i added on line 80 
filename2 = 'ScreenGrab2'
myfile2 = str(filename2)+str('1')+str('.jpg')
w.renderPixmap(1000,1000).save(myfile2)

Do you see anything wrong with this or do you not get the error?

Thanks

Mat




--
example.py

Luke Campagnola

unread,
Apr 24, 2013, 9:56:55 PM4/24/13
to pyqt...@googlegroups.com
On Wed, Apr 24, 2013 at 9:28 PM, Mathew Schwartz <umc...@gmail.com> wrote:
Hi Luke,

I have tested this on two computers, one with i3 integrated graphics, the other with i7 geforce gt 630M, the latter has opengl 4.2.    I attached an example file, its your scatter plot example and i added on line 80 
filename2 = 'ScreenGrab2'
myfile2 = str(filename2)+str('1')+str('.jpg')
w.renderPixmap(1000,1000).save(myfile2)

Do you see anything wrong with this or do you not get the error?


Aha! I do see this error. It isn't immediately clear to me why the error is only present when exporting, though. 
Thanks for being patient with me. I'll let you know if I figure this out..


Luke
 

Mathew Schwartz

unread,
Apr 24, 2013, 11:10:16 PM4/24/13
to pyqt...@googlegroups.com
Great, im happy it wasnt me being crazy.

Thanks!


--

Mathew Schwartz

unread,
Jun 16, 2013, 8:44:45 PM6/16/13
to pyqt...@googlegroups.com
Hi Luke, 

Did you ever get a chance to look into making the scatterplot render with Pixmap?  I was hoping to include some of my images using pyqtgraph at a gallery next month so it would be really nice if I could render it at a higher resolution.

Thanks

Luke Campagnola

unread,
Jun 16, 2013, 9:00:31 PM6/16/13
to pyqt...@googlegroups.com
I've still got this in my to-do-after-graduation list  :) 
Might I recommend exporting to SVG and use inkscape to render to higher resolution? That's what I've been doing for my publishables..
If that isn't an option, I'm happy to take a look at this sooner. 

Luke

Mathew Schwartz

unread,
Jun 16, 2013, 9:14:28 PM6/16/13
to pyqt...@googlegroups.com
That sounds like it should work for now, how are you exporting to svg?  

Luke Campagnola

unread,
Jun 16, 2013, 9:28:20 PM6/16/13
to pyqt...@googlegroups.com
The export dialog has a list of the available exporters. SVG should be in there..?

Mathew Schwartz

unread,
Jun 16, 2013, 9:31:49 PM6/16/13
to pyqt...@googlegroups.com
export dialog?  The scatterplot is in 3D, I thought it didnt have an export dialog...

Luke Campagnola

unread,
Jun 16, 2013, 11:35:58 PM6/16/13
to pyqt...@googlegroups.com
Ach! I forgot we were talking about 3D graphics. My apologies. After looking at this some more, I have concluded that QGLWidget.renderPixmap is just broken. There is some working export code here: 
d = w.renderToArray((1000, 1000))
pg.makeQImage(d).save(filename)

Let me know whether that works for you.

Luke

Mathew Schwartz

unread,
Jun 17, 2013, 4:55:34 AM6/17/13
to pyqt...@googlegroups.com
Thanks luke, where is makeQImage?  

Luke Campagnola

unread,
Jun 17, 2013, 7:28:53 AM6/17/13
to pyqt...@googlegroups.com
On Mon, Jun 17, 2013 at 4:55 AM, Mathew Schwartz <umc...@gmail.com> wrote:
Thanks luke, where is makeQImage?  

Just as written--it should be in the base pyqtgraph namespace. 

    import pyqtgraph as pg
    pg.makeQImage(...)

Mathew Schwartz

unread,
Jun 17, 2013, 8:23:39 AM6/17/13
to pyqt...@googlegroups.com
got it thank you.  its a bit more manual but it is working great. Thank you very much!!

Mathew Schwartz

unread,
Jun 17, 2013, 11:50:40 PM6/17/13
to pyqt...@googlegroups.com
Hi Luke,  When trying to render large images, 5k or 10k, I get memory errors.  Im pretty sure i have enough RAM, which is never above half when running the program, and my graphics card has 2 gigs RAM.  Do you have the same problem with large images?

Traceback (most recent call last):
  File "D:\MoAnProg\MoAnWin.py", line 1441, in Save3DCall
    d = globalMoAnWindow.openglwidget.renderToArray((int(arg[1]),int(arg[2])))
  File "C:\Python27\lib\site-packages\pyqtgraph\opengl\GLViewWidget.py", line 335, in renderToArray
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data.transpose((1,0,2)))
  File "C:\Python27\lib\site-packages\OpenGL\latebind.py", line 41, in __call__
    return self._finalCall( *args, **named )
  File "C:\Python27\lib\site-packages\OpenGL\wrapper.py", line 792, in wrapperCall
    raise err
OpenGL.error.GLError: GLError(
err = 1285,
description = 'out of memory',
baseOperation = glTexImage2D,
pyArgs = (
GL_TEXTURE_2D,
0,
GL_RGBA,
10000,
7493,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
array([[[0, 0, 0, 0],
        [0, 0, ...,
),
cArgs = (
GL_TEXTURE_2D,
0,
GL_RGBA,
10000,
7493,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
array([[[0, 0, 0, 0],
        [0, 0, ...,
),
cArguments = (
GL_TEXTURE_2D,
0,
GL_RGBA,
10000,
7493,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
array([[[0, 0, 0, 0],
        [0, 0, ...,
)
)

if I run it again i just get this error:

Traceback (most recent call last):
  File "D:\MoAnProg\MoAnWin.py", line 1441, in Save3DCall
    d = globalMoAnWindow.openglwidget.renderToArray((int(arg[1]),int(arg[2])))
  File "C:\Python27\lib\site-packages\pyqtgraph\opengl\GLViewWidget.py", line 329, in renderToArray
    data = np.zeros((w,h,4), dtype=np.ubyte)
MemoryError: <OpenGL.GL.images.ImageInputConverter object at 0x04FE1D90>

Luke Campagnola

unread,
Jun 18, 2013, 11:03:57 AM6/18/13
to pyqt...@googlegroups.com
On Mon, Jun 17, 2013 at 11:50 PM, Mathew Schwartz <umc...@gmail.com> wrote:
Hi Luke,  When trying to render large images, 5k or 10k, I get memory errors.  Im pretty sure i have enough RAM, which is never above half when running the program, and my graphics card has 2 gigs RAM.  Do you have the same problem with large images?

I thought that might end up being an issue. The problem is probably not that you are out of memory, but rather that there is no contiguous block of memory large enough for the texture. Have a look at the latest version--it now breaks up the export into 512x512 chunks and reassembles them.


Luke

 

Mathew Schwartz

unread,
Jun 18, 2013, 8:09:16 PM6/18/13
to pyqt...@googlegroups.com
The update is able to do 10k images but the textures are not aligning well for me.  I am also only able to save an image once, then the memory issue comes up again:
Traceback (most recent call last):
  File "D:\MoAnProg\MoAnWin.py", line 1557, in Save3DCall
    d = globalMoAnWindow.openglwidget.renderToArray((int(arg[1]),int(arg[2])))
  File "C:\Python27\lib\site-packages\pyqtgraph\opengl\GLViewWidget.py", line 355, in renderToArray
    output = np.empty((w, h, 4), dtype=np.ubyte)
MemoryError

So this makes a big problem when rendering multiple images.   Is it possible to clear the memory it uses for saving or this is just a problem with python in general?  Similarly, is it possible to hardcode the contigous block of memory to be large enough for the files.  Our lab has computers with 32 gigs of ram so i imagine it could store some large images.  

Thanks


--

Luke Campagnola

unread,
Jun 18, 2013, 8:18:44 PM6/18/13
to pyqt...@googlegroups.com
On Tue, Jun 18, 2013 at 8:09 PM, Mathew Schwartz <umc...@gmail.com> wrote:
The update is able to do 10k images but the textures are not aligning well for me.

Can you send me an example? 
 
 I am also only able to save an image once, then the memory issue comes up again:
Traceback (most recent call last):
  File "D:\MoAnProg\MoAnWin.py", line 1557, in Save3DCall
    d = globalMoAnWindow.openglwidget.renderToArray((int(arg[1]),int(arg[2])))
  File "C:\Python27\lib\site-packages\pyqtgraph\opengl\GLViewWidget.py", line 355, in renderToArray
    output = np.empty((w, h, 4), dtype=np.ubyte)
MemoryError

If you have PyQt 4.10, you might be running into this issue: https://groups.google.com/forum/#!topic/pyqtgraph/JkIQNFDin_g
I am hoping the PyQt folks will have some solution, because otherwise I will just have to tell people to revert to 4.9 (or use pyside).
 

Luke

Mathew Schwartz

unread,
Jun 18, 2013, 8:36:21 PM6/18/13
to pyqt...@googlegroups.com
Do you know of anything I should be aware of reverting to 4.9,  if it fixes the problem then I have no problem reverting, at least for this rendering.  Is my thoughts on allocating memory totally off base for python?


--
10ktest_0.jpg

Mathew Schwartz

unread,
Jun 18, 2013, 9:17:54 PM6/18/13
to pyqt...@googlegroups.com
4.9 did help with saving multiple images, but the texture maps still have the problem of alignment, in the 2k images.  (attached example)
_704.jpg

Luke Campagnola

unread,
Jun 18, 2013, 9:49:11 PM6/18/13
to pyqt...@googlegroups.com
On Tue, Jun 18, 2013 at 8:36 PM, Mathew Schwartz <umc...@gmail.com> wrote:
Do you know of anything I should be aware of reverting to 4.9,  if it fixes the problem then I have no problem reverting, at least for this rendering.  Is my thoughts on allocating memory totally off base for python?

4.9 has been pretty good to me. I'd recommend staying there at least until the memory issue is resolved. 
Regarding your images: are they animated? And if so, is it possible that the content is changing in between each of the sub-image renders? 
(I could be more helpful with a code example than a screenshot)

There are two memory issues here: The first is that generating a QImage from a numpy array in PyQt4.10 increases the reference count to the array but neglects to decrease the reference count when it is finished with the image. So python will refuse to free the memory held by the array because it thinks some part of the program is still using it. As far as I know, there is no way to simply force python to delete the array. 

The second problem is that memory can become fragmented. So even if you have 2GB of video memory, it is full of small textures and buffers that occupy various places in the memory. Thus, the largest contiguous piece of free memory is probably much smaller. This is a general problem with pretty much all fragmenting storage systems, and is not limited to python at all. This problem was also aggravated by the fact that I forgot to delete the texture from video memory after the export (duh), although it's not much of a problem in the version you have because it's only 1MB. 


Luke

 

Mathew Schwartz

unread,
Jun 18, 2013, 11:50:09 PM6/18/13
to pyqt...@googlegroups.com
The 10k image is a single plot, no animation.  The second image is part of an animation sequence which recreates the entire view each time with a new color, so if it was updating in between it would go from red to blue.

So after the revert to 4.9 the only memory issue i run into is with larger than 10k, like 15k still gives me memory issues but maybe expecting that is out of reach for now anyway.  The alignment of the subtextures does seem to still be a problem, are you not able to see that?  The code is so intermixed with a larger program but if you are not able to see the same thing i will try to recreate the situation 


--

Luke Campagnola

unread,
Jun 19, 2013, 9:15:04 AM6/19/13
to pyqt...@googlegroups.com
On Tue, Jun 18, 2013 at 11:50 PM, Mathew Schwartz <umc...@gmail.com> wrote:
The 10k image is a single plot, no animation.  The second image is part of an animation sequence which recreates the entire view each time with a new color, so if it was updating in between it would go from red to blue.

So after the revert to 4.9 the only memory issue i run into is with larger than 10k, like 15k still gives me memory issues but maybe expecting that is out of reach for now anyway.  The alignment of the subtextures does seem to still be a problem, are you not able to see that?  The code is so intermixed with a larger program but if you are not able to see the same thing i will try to recreate the situation 

I found it--after the scatter plot points exceed a certain size, they start getting clipped. The latest version renders some padding around each section to avoid this. You might need to play with the textureSize and padding arguments, depending on the size of your points (but always make sure textureSize > 2*padding).

Luke

Mathew Schwartz

unread,
Jul 4, 2013, 9:48:21 PM7/4/13
to pyqt...@googlegroups.com
its great and working thanks!!


--
Reply all
Reply to author
Forward
0 new messages