-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pdf files are HUGE #517
Comments
I believe there is. I will ask David Lonie as he added that feature into the VTK. |
Can someone point me towards a sample script to generate a problematic PDF? I have some ideas that might fix this... |
I just grabbed a random boxfill script, hopefully this is a good representation of the issue...? Also, "huge" isn't very descriptive -- How big are the files you are seeing, and how big are the references you're comparing them to? I used:
The generated file is 453k and breaks down into the following:
There's not a whole lot that can be done on the exporter side to tighten things up -- it's only drawing the visible primitives in the scene, and compresses the bulk of the data (the triangles) into a binary representation. Suggestions to make them smaller:
|
you're right the size seems reasonable, again, i'll try to find the "complicated" example where the size was in 10s of Mb. |
closing it now.. if we find that its an issue again. .then we will create a new one or reopen this one |
Re-opened just in case. |
Unassigning myself -- can't do much about this without an example ;) |
Right.. assigning it to Charles for now as we need to have an example. |
all right data is at:
|
also file is 54Mb |
Took a look -- some first thoughts: SizeNot much we can do here. Postscript is a verbose text format, and this script is pushing a 1441x401 grid into it. The data gets rendered as a set of triangles, so for that size grid, we get
which is the postscript command to draw a triangle between the specified vertices. We can count them with Incidentally, the file consists of 1,157,874 lines, which means the boxfill triangles are roughly 99.5% of the file. tl;dr If the data is this big, expect a large postscript file. If you want the file to be smaller for transfer/storage, consider compressing it with gzip (goes to 6.2MB) or bzip2 (goes to 4.8MB). If you want to reduce the size of the data in the file, it will need to be downsampled prior to exporting. But in any case, if we specify >1M triangles to go into the file, they will require a lot of space. TimeThe overflow warnings are the result of GL2PS using too small of a memory buffer to hold the postscript instructions that it's building, and having to reallocate memory. When the buffer is exhausted like this, the exporter prints the "overflow" warning, doubles the buffer size, and restarts the render, so most of the time went into this export was spent in failed write attempts. If we're going to be regularly exporting data this large, I can add an option to the VTK layer of the exporter to specify the initial buffer size -- this would potentially reduce the number of overflows and export attempts and speed things up by (in this particular case) a factor of ~10. Big black squareFor some reason, that postscript file is specifying every triangle as black, meaning that somehow the colors aren't being rendered in a way that makes it through to the OpenGL feedback buffer. I can look into this. However, be warned that once this is fixed, the file will get approximately 30% larger, since specifying colors for the triangles will need space, too. In short:
|
@dlonie thanks for looking into this. I agree the size might be ps related, but pdf is about 5Mb. Didn't try svg. |
PDF uses compression internally -- it basically takes the draw instructions and runs them through gzip or similar before storing them in big binary blobs in the file. Hence why the pdf export is roughly the size of the gzip'd postscript format. Postscript doesn't offer anything similar -- the format specifies raw text, and any compression has to happen externally, either through manual compression with gzip/bzip, or setting vtkGL2PSExporter::CompressOn() to produce a gzip'd file automatically. SVG would be similar to postscript, maybe a little larger due to the xml markup overhead. The image looks fine on-screen for me when rendered. I'm not sure why the color information is being lost between the rendering and OGL feedback buffer, though. Very odd. |
I dug around in our polydata rendering implementations, and the UVCDAT fork of VTK is still using OpenGL fixed pipeline APIs for rendering, which should definitely work with GL2PS. I'll investigate more deeply after we bump VTK to current master, as the rendering backends have been reworked a lot in recent months and may include a fix. |
@dlonie on that note, @aashish24 stated on Monday that this VTK update should be done by today. Is that still valid? I'm really looking forward to seeing the bug fixes it's supposed to bring in. |
VTK is now updated. @dlonie if you can fix/verify the color issue then we can close this issue. |
hum... Before we close this issue can we implement the cache fix that @dlonie mentioned. |
Cache fix? |
buffer fix, sorry multitasking here 😉
|
Got the buffer changes in locally, and started debugging the color issue. @doutriaux1 Can you confirm that the postscript file resulting from this script is missing the color data? I've confirmed that we're feeding the colors into OpenGL correctly, but for some reason the colors in the feedback buffer (which GL2PS uses to build up the postscript file) are all rgba=(0,0,0,0). This makes me think it might be a driver bug on my machine, since the color info disappears while OpenGL is processing the scene. |
I take that back -- the colors are coming out in the feedback buffer. gl2ps seems to be dropping them somewhere. I'll keep looking. |
#1016 fixes the buffer issue, and http://review.source.kitware.com/#/t/5443/ Still looking into the color issue. It's very strange... |
I think I've figured out what's going on with the colors.
Since we're now running into viewer limitations, I think this is as good as it gets from the export side of things, short of rasterizing the boxfill data into the vector image. |
ok, should I try and approve this ? |
Sure, #1016 can go in whenever. The only difference it should make is faster export times 👍 |
Closing with a quote from "Limitations" section of the GL2PS website (http://www.geuz.org/gl2ps/), which summarizes the issue well: "Rendering large and/or complicated scenes is slow and/or can lead to large output files. This is normal: vector-based images are not destined to replace bitmap images. They just offer an alternative when high quality (especially for 2D and small 3D plots) and ease of manipulation (how do you change the scale, the labels or the colors in a bitmap picture long after the picture was produced, and without altering its quality?) are important." |
@aashish24 there must be a way for VTK to produce smaller pdfs no?
The text was updated successfully, but these errors were encountered: